Last post Nov 15, 2009 01:48 AM by RickNZ
Nov 09, 2009 10:47 AM|jschumann|LINK
I am trying to create a website that when a user types in a url like this
http://www.something.com/option1/option2/option3 it uses rewriting to go to
I have a website hiearchy in mysql. I want to be able to take what they have for option1, option2, and option3 to go through the hiearchy and get the id.
I do not have access to iis. I know it is has iis 7 and Microsoft URL Rewrite is installed. I have read some solutions about going into iis 7 and using the * to handle folder urls. I don't have access to do that.
Is there a to handle what I'm looking for? I have created a httpmodule which works for .aspx extensions. I just need some way of doing this when I don't have extensions.
Nov 09, 2009 11:03 AM|uid117455|LINK
You can do this without having to access IIS by doing the following:
1. Create Global.asax in your website
2. In Application_BeginRequest you can add code to detect what URL has been specified and then do a rewrite to the actual URL you require to display that page, e.g.
string targetUrl = ""; // This needs to be the actual URL you're trying to map the friendly URL to, so you'll need some code to pair the two together
Remember you'll probably only want to do this for .aspx files! Css, images, etc., should probably be allowed to do their "usual" thing without rewriting.
I found this article by Scott Guthrie to be very helpful with understanding URL rewriting:
Nov 09, 2009 11:16 AM|jschumann|LINK
Yeah, I have looked at the link alot. That works for .aspx, however I need it to work for extensionless urls. Approach 3 has a way to handle extensionless urls by putting a rewrite section within your web.config. The problem I have is that my website hiearchy
may have changed by addition and removal of pages.
I wonder if I could have all requests go through a single rewrite url. From there I could determine if it is extensionless and then at that point do a rewrite?
Nov 15, 2009 01:48 AM|RickNZ|LINK
If you use an HttpModule instead of Global.asax, and register the HttpModule so that it runs in Integrated mode, (preCondition="integratedMode"), then the HttpModule will run with static files as well as with .aspx files -- that should include extensionless
URLs, too, provided you catch them early enough in the pipeline before IIS rejects them as 404 Not Found.