Tip/Trick: Url Rewriting with ASP.NET
page 2 of 6
by Scott Guthrie
Average Rating: 
Views (Total / Last 10 Days): 89421/ 98

Why does URL mapping and rewriting matter?

The most common scenarios where developers want greater flexibility with URLs are:

1) Handling cases where you want to restructure the pages within your web application, and you want to ensure that people who have bookmarked old URLs don't break when you move pages around.  Url-rewriting enables you to transparently forward requests to the new page location without breaking browsers.

2) Improving the search relevancy of pages on your site with search engines like Google, Yahoo and Live.  Specifically, URL Rewriting can often make it easier to embed common keywords into the URLs of the pages on your sites, which can often increase the chance of someone clicking your link.  Moving from using querystring arguments to instead use fully qualified URL's can also in some cases increase your priority in search engine results.  Using techniques that force referring links to use the same case and URL entrypoint (for example: weblogs.asp.net/scottgu instead of weblogs.asp.net/scottgu/default.aspx) can also avoid diluting your pagerank across multiple URLs, and increase your search results.

In a world where search engines increasingly drive traffic to sites, extracting any little improvement in your page ranking can yield very good ROI to your business.  Increasingly this is driving developers to use URL-Rewriting and other SEO (search engine optimization) techniques to optimize sites (note that SEO is a fast moving space, and the recommendations for increasing your search relevancy evolve monthly).  For a list of some good search engine optimization suggestions, I'd recommend reading the SSW Rules to Better Google Rankings, as well as MarketPosition's article on how URLs can affect top search engine ranking.

View Entire Article

User Comments

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

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: 2009-08-06 1:33:47 AM
nice article
Title: Found another working example   
Name: Samira
Date: 2009-04-07 2:32:22 AM
nice article but has few problems..i found another working article with example
Title: nike shoes   
Name: nike shoes
Date: 2009-04-06 11:37:24 PM
very good...
Title: Nice article, shame you copied it   
Name: Don't Copy Other People's Work
Date: 2009-01-25 4:39:02 PM
Nice article, shame you copied it
Title: not working   
Name: milap
Date: 2008-05-12 6:46:39 AM
hi please any example available for url rewriting then put here with code.
Title: not working   
Name: milap
Date: 2008-05-12 6:44:31 AM
Hi in this website download link is not working so please check this.
Title: Not running on IIS localhost   
Name: rajiv Sharma
Date: 2008-03-15 2:03:09 AM
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: 2008-02-20 3:27:59 PM
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: 2008-02-12 6:29:31 AM
Very information and well written - thanks
Title: in a shared hosting environment   
Name: Carlos Martinez
Date: 2007-12-04 9:55:29 AM
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: 2007-05-19 12:43:56 AM
please help me config on server
Title: can not run on server   
Name: bang
Date: 2007-05-18 9:40:10 PM
can not run on server
please help me
thank you

Product Spotlight
Product Spotlight 

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

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-06-24 8:39:26 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search