UPDATE: This method indeed worked; it can redirect the extensionless request to ASP.NET ISAPI. However, there’s still a problem with it. If the request includes parameters, for some reason, it changes the url to include ‘default.aspx’ thus breaking the code. For example: http://mysite.com/dostuff/?param=somevalue will be redirected to http://mysite.com/dostuff/default.aspx?param=somevalue. Anyone got any solution to this?
It is getting more and more common to see websites without “file extensions”, such as .php, .aspx, or others. This is possible with the aid of url rewriting technique. I tried UrlRewriter.NET, and I kinda liked it for it’s simplicity and flexibility.
It all worked just fine in my development machine, but when I uploaded the code to my hosting (shared hosting), everything just broke. Turns out it has some limitations (Note: This limitation occurs only for url’s without extensions, or url with extensions that is not configured in IIS). The reason for that, is IIS needs to know which HTTP request to be forwarded to ASP.NET ISAPI handler (at least until 5.1. I heard that IIS7 could overcome this problem via config, instead of modifying IIS settings). Only extensions configured in IIS will be redirected to ASP.NET ISAPI handler.
For those requests lucky enough to be passed to ASP.NET ISAPI handler, it will follow the HTTP Request Pipeline, and if it’s configured, it will go through UrlRewriter module first. For requests that are not passed to ASP.NET ISAPI handler, IIS will try to redirect it to the physical resource location on the server. For example: http://mysite.com/register/ will be redirected to folder register and try to load the default page (depends on the configuration, whether it’s default.aspx or others).
Lucky enough, I found a way to overcome this problem without having to forcing our way into the IIS configuration (even though this method might be quite irritating). The keyword is that “IIS will try to find the physical resource location on the server”. So, as Gil Grissom (CSI) once said, “If Mohammed won’t go to the mountain, then the mountain must go to Mohammed”, LOL. Anyway, so if IIS insists on finding the physical resource, let’s give him one. So, if you have one url rewriting configuration like /register, all you have to do is to create a folder called register, and don’t forget to at least create one file named to the default page filename (i.e. default.aspx, etc). And voilla, it worked.
PS: Don’t forget to do this step for every url rewriting configuration you have.
RSS feed for comments on this post · TrackBack URI
Leave a reply