Tip/Trick: Url Rewriting with ASP.NET
page 1 of 6
Published: 26 Feb 2007
Unedited - Community Contributed
Abstract
In this article Scott examines the concept of URL rewriting in ASP.NET using code samples.
by Scott Guthrie
Feedback
Average Rating: 
Views (Total / Last 10 Days): 60519/ 373

Introduction

Republished with Permission - Original Article

People often ask me for guidance on how they can dynamically "re-write" URLs and/or have the ability to publish cleaner URL end-points within their ASP.NET web applications.  This blog post summarizes a few approaches you can take to cleanly map or rewrite URLs with ASP.NET, and have the option to structure the URLs of your application however you want.


View Entire Article

User Comments

Title: Url Rewriting made Easy   
Name: ashish
Date: 9/6/2010 3:37:08 PM
Comment:
Very useful article. I liked it. Thanks a lot.
Title: Url Rewriting with ASP.NET   
Name: http://apps.facebook.com/socialcontest
Date: 8/21/2009 5:18:20 AM
Comment:
Hi,


I am using url rewriting and Ajax, now wherever anything related to ajax is done and the page is posted back, the postback url changes(i.e. its adding the directory name in the url) coz of which iam getting the following javascript error and i can't move forward.



Error: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500


I know it is an issue which lot of people are facing but how can i make url rewriting work with ajax..

The code which i have been using in Global is as follows:

string url = HttpContext.Current.Request.Url.AbsoluteUri;

if (url.Contains("404.aspx"))
{
string urlInfo405 = HttpContext.Current.Request.Url.AbsoluteUri;

string[] urlInfo404 = urlInfo405.Split(';');
string urlMain = urlInfo404[1];



string urlpath = urlMain.Replace("//", "/");

string[] urlInfo = urlpath.Split('?');
string path = urlInfo[0];
string[] currentPath = path.Split('/');


Context.Items.Add("Original_Path", currentPath[2] + ".aspx?cname=" + currentPath[3] + "&" + urlInfo[1]);
Context.RewritePath(currentPath[2] + ".aspx?cname=" + currentPath[3] + "&" + urlInfo[1],false);


I have even used Context.Items.Add which will fix my url for the entire post-response cycle.

Any guidance
Title: Nice article,   
Name: Baljeet Bhardwaj
Date: 8/6/2009 1:33:47 AM
Comment:
Hi..
nice article
Title: Found another working example   
Name: Samira
Date: 4/7/2009 2:32:22 AM
Comment:
Hi..
nice article but has few problems..i found another working article with example
see
http://dotnetkeeda.blogspot.com/2009/04/url-rewriting-mapping-in-aspnet.html
Title: nike shoes   
Name: nike shoes
Date: 4/6/2009 11:37:24 PM
Comment:
very good...
Title: Nice article, shame you copied it   
Name: Don't Copy Other People's Work
Date: 1/25/2009 4:39:02 PM
Comment:
Nice article, shame you copied it
Title: not working   
Name: milap
Date: 5/12/2008 6:46:39 AM
Comment:
hi please any example available for url rewriting then put here with code.
Title: not working   
Name: milap
Date: 5/12/2008 6:44:31 AM
Comment:
Hi in this website download link is not working so please check this.
Title: Not running on IIS localhost   
Name: rajiv Sharma
Date: 3/15/2008 2:03:09 AM
Comment:
Hi I am trying to use it, its working fien with ASP.NET Development Server, but it is not running on localhost (IIS) server, please help me. rajrunatserver@gmail.com
Title: QueryString   
Name: Hugo
Date: 2/20/2008 3:27:59 PM
Comment:
Very good your article!!! Fantastic!

One more question... How can I do for this url: http://localhost:49195/UrlRewrite_HttpModule1/Products/Books.aspx?varB=1&varB=xxx

I want read querystring too...

Thanks. You can reply to me for hgoncalves@gmail.com
Title: Great Article   
Name: Adam Lock
Date: 2/12/2008 6:29:31 AM
Comment:
Very information and well written - thanks
Title: in a shared hosting environment   
Name: Carlos Martinez
Date: 12/4/2007 9:55:29 AM
Comment:
Hi, You said the first approach could work in a shared hosting environment. however, we always have to configure the IIS server when deployment. Or there is another option?? I have this problem now, and I have asked my hosting to allow me that.
Title: please help me config on server   
Name: bnet
Date: 5/19/2007 12:43:56 AM
Comment:
please help me config on server
Title: can not run on server   
Name: bang
Date: 5/18/2007 9:40:10 PM
Comment:
can not run on server
please help me
thank you

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2014 ASPAlliance.com  |  Page Processed at 7/31/2014 5:26:24 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search