Problem 1: Page Postback for Page displaying URL Rewritten URLPage Postback of Page displaying User friendly URL will turns into original state when same page postback occurs. In our example, I am adding one button and trying to make Page Postback. You will notice that Page Postback will turns the User Friendly URL into original URL containing QueryString.

This article is inspired from Scott's URL Rewritten article. Adding two files as mentioned by scott. If you are developing code in VB download files from Scott's article, else for C# download files with Sourcecode at the end of this article.

Now, lets test the Page Postback by clicking on Button, you will notice this time, URL remains the same.

Problem 2: Image Display ProblemNow, lets display image on for this page and lets observe what problem we may run into. I have added following line to display image, but it won't works.

103 comments:

Manish
said...

It is nice article. I was looking for tutorial on URLRewriter.Net and it was useful to me, but i am confuse whether we should use hypen "-" or underscore "_" for replacing space while making url seo friendly. Thanks for sharing.

Its a perfect solution i was searching for url rewriting for asp.net application. Can you update your article to show how can i handle multiple or two or more querystring value to handle url rewriting request.

Its a easiest solution i came across and more practical to what i am looking for.

this example wokring on local server well but when i am moving on pre production server is not wokring giving me "HTTP Error 404 - File or directory not found."is any setting in IIS 6.0 for using this urlrewriting..Please help me out ASAP.Thanks Dinesh

[NullReferenceException: Object reference not set to an instance of an object.] Intelligencia.UrlRewriter.Configuration.RewriterConfiguration.Load() +102 Intelligencia.UrlRewriter.Configuration.RewriterConfiguration.get_Current() +169 Intelligencia.UrlRewriter.RewriterHttpModule..cctor() +47

[TypeInitializationException: The type initializer for 'Intelligencia.UrlRewriter.RewriterHttpModule' threw an exception.]

I don't think that Session can create problem, I strongly feel that you might be setting up or may be session value is overridden somewhere in project. One tip, why don't you search for "session" - ctrl+shift+f (In entire solution) it will give you all the places where session is declared and you can verify it.

Dear Sir.I'm one of who read this article as bible for url-rewriting.It's perfect and really good for me, but problem was it's fine on my local but not on the pre-production server (like Dinesh said in earlier posting)

I know you said him to check firewall, and he said "thnx" but for me ... :(Actually I'm using GoDaddy.com as pre-production server, and no way to get to know if firewall is on.

This problem makes me crazy for 1 week.I'll really appreciate if you let me know any other hint that might cause this problem, or any experience with GoDaddy.com like "hey, the firewall is on there!".

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Sorry I not correct say. I used Web Control "Login" <asp:Login ID="Login1" runat="server"> And I add two files in my project FormRewriter.cs and Form.browser. And action in forms tag get rewrite url. And when I used any other web control sort of works. But when I clicked Login Control, not work.I used Login control how block authenticationSorry for my English

Great stuff. The only actual sample I saw. I used it as a base for my own sample in vb.net using the Northwind SQL Server database. See http://www.corobori.com/Blog/es/post.aspx?id=5d13a0d4-6882-4154-85de-dd4687a62c6f

I use your example of re-write and it working on first time page load event,but in the time of fire a page event (like button click) it not working properly.It show actual Page url.I am using Asp.net 2.0 and ajax control tool kit.Waiting for your early reply.

The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Please have look at this page http://www.purpleculture.com/a-photographic-guide-to-birds-of-china-b-34ed6c52ab37.html. There is a "add this to my cart" button in this page, when clicked, the URL will be changed into http://www.purpleculture.com/a-photographic-guide-to-birds-of-china-b-34ed6c52ab37.html?action=add_product.

I've added the following rule rewrite url="~/(.*)-b-(.+).html(.*)?$" to="~/index.php?main_page=product_book_info&products_id=$2${encode($3)}" , but the "?action=add_product" part doesn't work. Do you have any idea?

I have an application where a user logs in and becomes authenticated. On pages where the url has not been rewritten, the request shows as authenticated. On the url rewritten pages, however, the authentication cookie is present but IsAuthenticated returns false. I can browse back to the non rewritten page and is shows correctly as true. It definitely appears related to url rewriter. AS you can imagine this messes up any controls that use templates for logged in users. Any ideas?Thanks

Seems like i have same poblem Программист had. When i signin using Login Control, the urlrewriter dont work. To resolve this i have to use Redirect after login but it isnt userfriendly ;). Any ideas how to fix this? Mayby smth in FormRewriter.cs ?

Hi.i have implemented this and its working in local.now i have uploaded it on server but its giving me error like this :

The page cannot be foundThe page you are looking for might have been removed, had its name changed, or is temporarily unavailable.

Please try the following:

* Make sure that the Web site address displayed in the address bar of your browser is spelled and formatted correctly. * If you reached this page by clicking a link, contact the Web site administrator to alert them that the link is incorrectly formatted. * Click the Back button to try another link.

this is my stuff in web.config<add key="/rewrite.net/test.aspx" value="http://www.prabir.me" />It should rewrite (not redirect) to prabir.me domain which is totally differnt domain. when i go to type http://www.olddomain/rewrite.net/test.aspx yelow screen of death comes saying "The given path's format is not supported."Is my rule correct?

YOU NEED TO UNDERSTAND THAT IF YOU INPUT GARBAGE IT WILL RETURN GARBAGE, SO IF YOU ARE BUILDING HARDCORE URL INSTEAD OF RELATIVE URL, THAN YOU WOULD DEFINITELY FACE THIS PROBLEM. Try to form Relative path while creating url, and it would run good on server too.

2 Jony ShahYes, I have wrote my own module which catches the 404 error from IIS 6 and uses the "action" attribute of the html form. I stuck at postback. Everything works fine, but when user doing postback in browser he seeing url like "http://site.com/404.aspx?404;http://site.com/category/4" because this "dirty" url situated in the "action" attribute. This is bad but it works.How you handle this problem?

Hello,Great article. I have implemented url rewriting on my test page in the same way as it was written in article. All works good. But when I hook up existing sites to master page the default.aspx is not hidden in address bar. Withoud master page, the default.aspx is invisible in address bar. Except this unhidden default site name, all works good with master page. I suppose that it is connected with Form.browser but my knowledge of asp.net is insufficient to find solution myself. Did anybody of You meet this problem? How to handle this?

2. Change the order of rewrite url from bottom up approach. That is url which has maximum number of query string should come first in sequence and one with less no. of query string parameter turns after that.

So being said that you need to change order of rewrite tag in web.config file to following

Hello Sir, In the application, I have a folder named Shops. When I enter http://localhost:2141/sample/Shops/shopname/ it should go to the detail page of particular shop. The rule I have put like thisrewrite url="^~/Shops/(.*) to "~/Shops/detail.aspx?Id=$1" But the thing is that when the user type in http://localhost:2141/sample/Shops/ i want to redirect it to http://localhost:2141/sample/Shops/default.aspx . But now this is also redirecting to http://localhost:2141/sample/Shops/shopname/ Could you plz suggest a solution?

I may have missed something since I am quite tired at the moment. but when loading the rewritten URL my grid remains unfiltered because it requires a querystring to filter results. How can you order the gridview to treat an integer in the document name as if it were a querystring?

The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

I am getting lot of email about saying that their URL Rewriting is working good in Local Environment, but when it goes to Production Environment it is giving 404 - Page Not Found Error

Solution------------1) Please don't use hard-coded url2) Play with URL Rewriting Path, their is nothing wrong with any other part of URL Rewriting as it is running in Local3) Try to use ResolveUrl() function while generating link.

I am using this piece of code on many of my development work and it is working like charm.

People who are facing 404 - Page not found error, your attention please. I was facing this problem after uploading the website onto the production server and spent lots of my time trying to get away with this error, i also posted my query in this forum. Ultimate i found that you need to set the property runAllManagedModulesForAllRequests="true" of module element in web.config file. I started programming for the website and when i need the url rewrite solution i came accross this article since i already had web.config file in my project i did not copy the entire web.config from this article but copied required elements from the web.config mentioned here. But fogot to set the above mentioned property of module element. Which may be the case with everyone who are facing the Page not found error. All you who are facing this error, i request them not to foget to set the runAllManagedModulesForAllRequests="true" in module element. We tend to forget this which is very important else the url rewrite not work.

This article was wonderful and it works like char in the production server. My special thanks to the author of this article. Hope my suggestion helps those who are facing Page not found error.

Hi, Thanks for a great tool, I had this up and running within a matter of minutes but I have a small issue with which I may be missing an obvious point?

I have a two pages running in root:

ShowMeTowns.aspx?town=1ShowMeVenues.aspx?venue=1

I want to display the link for ShowMeTowns.aspx as www.mydomain.com/Abingdon.aspxwww.mydomain.com/Aldershot.aspxwww.mydomain.com/Andover.aspx

etc etc instead ofwww.mydomain.com/ShowMeTowns.aspx?town=1

so I followed your insructions along with an entry into the web.config:rewrite url="~/(.+)-(.+).aspx" to="~/ShowMeTowns.aspx?town=$2"/

which of course worked perfectly. But now I want to set up ShowMeVenues.aspx in the same way so I repeated the instructions and included another entry to the web.config:rewrite url="~/(.+)-(.+).aspx" to="~/ShowMeVenues.aspx?venue=$2"/

but when I run this it seems because they are both running in the root there is nothing to decifer which page it needs to redirect so the urls do change but in both instances the redirect goes to ShowMeTowns.aspx as this is the first one it comes to in the web.config. Can you tell me what the key is to seperate them. Do I need two different rules in the web.config, if so what format would they be?Thanks for any help in advance and apologies if I am missing the obvious!

Thanks for the reply. I had already tried your solution which worked well but I needed one of the urls to be dynamic and one to be static so after alot of tweaking I came up with this as my best solution:

This way it will either allow me to pass in the venue town so it would appear in the url as:

www.mydomain.com/townname/venuename.aspx

or I can pass in a fixed extension such as 'venuesin' so my url would appear as:

www.mydomain.com/venuesin/townname.aspx

This way I can show a list of towns and click through to venues in that town and list the selected town in the url and then from there, click on a town to click through to a venue which would then have the town and the venue name in the url.

I hope this makes sense!

This is a great solution for me and hopefully it will help someone else out, so thanks again for all your help with getting to where I wanted to be, im very happy with the solution I have!

Great article, however I just wanted to know if it is possible to strip off the Title Id from the url after it has been rewritten. so something like /Article/Asp-Net-website-paths.aspx instead of /Articles/Asp-Net-website-paths-1.aspx. Now I do realize that the title id is important inorder to get the title name but just wondering if there is anything that i can do to remove the number from the generated url.

Hello,it's really amazing work but when i used it with a project [.Net framework 4.0]it's worked very fine but when i used it with a project [.Net framework 2.0] i got this error [Failed to map the path '/Rewritable%20url/Default3.aspx/].Please help me ASAP thank you...

hello i ve just rename my solution and project names(18 projects inside) but the problem with intellengcia , it get s me error(page not fund 404 error) while its is working in original website.all web.config configuration for rewriting are same as original website but it si not working in renamed new website.i ve referenced to dll etc set configuration but still getting 404 error on all rewritten url, what could be the problem.

Hi, I am implementing this rule in two page and in web config I change according to this but it always goes to first page. like I have two page 1. pressrelease.aspx and 2. solution.aspxfrom press release it working fine but from solution pages it again redirect to press release landing page

Hello I found your post very useful.But i want to create a url rewriting in which each user can set their own url with username.Example www.abc.com/user1www.abc.com/user2 etc(similar to facebook,twitter).The username is already stored in the database how i can achieve this.Your response will be appreciated.

@DotNetGuts, Thanks for replying...I went through the link and found it useful but i am still using 2.0 so it would be better if i use the above mentioned code. So can you please help me sorting out the problem.

Most Recent Post

Community Updates

Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.