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): 93371/ 95

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: 2010-09-06 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: 2009-08-21 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: 2009-08-06 1:33:47 AM
Comment:
Hi..
nice article
Title: Found another working example   
Name: Samira
Date: 2009-04-07 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: 2009-04-06 11:37:24 PM
Comment:
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
Comment:
Nice article, shame you copied it
Title: not working   
Name: milap
Date: 2008-05-12 6:46:39 AM
Comment:
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
Comment:
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
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: 2008-02-20 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: 2008-02-12 6:29:31 AM
Comment:
Very information and well written - thanks
Title: in a shared hosting environment   
Name: Carlos Martinez
Date: 2007-12-04 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: 2007-05-19 12:43:56 AM
Comment:
please help me config on server
Title: can not run on server   
Name: bang
Date: 2007-05-18 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-2024 ASPAlliance.com  |  Page Processed at 2024-03-19 3:01:09 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search