IIS7 and Url Rewriting
IMPORTANT UPDATE
I found out where the
I was running in Classic .NETĀ AppPool, when switching to the DefaultAppPool in IIS7 I could use the
<modules runallmanagedmodulesforallrequests="true">
<add name="RedirectEngine" type="RedirectEngine.Rewrite, RedirectEngine" precondition="managedHandler"></add>
</modules>
<validation validateintegratedmodeconfiguration="false"></validation>
No idea what the last tag does, but IIS7 placed it there, so I hope it does any good š ** **Continue with (old) articleā¦ I have this website that needs to pump out some information to another application, just plain old xml. The problem is that this application was originally calling some weird app that was accessed through these kind of urls:
- http://myserver/folder/giveme?id=120
- http://myserver/folder/iwanttoknow?id=120&more=1
So my solution was to place a backslash, so youād get http://myserver/folder/giveme/?id=120.That way, it would be redirected to default.aspx and handle the request. Unfortunately, not an option, as the url was created by the calling application, based on just the domain. So after /myserver/ I had no control over the url it looked at.
My alternative was url rewriting. When thereās a request to some file, check the last part of the folder requested and redirect it to the right folder with a nice default.aspx in it. Until I ran into IIS7.
**IIS7
**The problem here is, that the request to non existing files donāt pass my HttpModule anymore! I just get a 404 and no breakpoint inside my code gets hit. In IIS6 every incoming call is forwarded to my HttpModule. I kept on seeing requests for favicon.ico for example. Not in IIS7 though.
Donāt ask me what I tried to get it working. I looked at Scott Guthrieās blog, but couldnāt find anything useful. Except this item, where Scott says youāll have to configure IIS7 to make it work. Sure, thanks Scott, but how?! I also found this forum thread on iis.net but have no idea where the
So whatās my solution? I added a handler to IIS, which seems possible inside your web.config since IIS7.I added the following:
<system.webserver>
<handlers>
<add name="MyFiles" path="*" verb="GET" modules="IsapiModule" scriptprocessor="%windir%Microsoft.NETFrameworkv2.0.50727aspnet_isapi.dll" resourcetype="File"></add>
</handlers>
</system.webserver>
So now every unknown file extension will be redirected to the ASP.NET Isapi module. Meaning itāll go through my HttpModule and I can redirect the request. This isnāt all though, it still wonāt transfer calls to me if thereās no file. So for every request thatās made, youāll have to figure out what the file should be and place one in the folder. My files are, based on my demo urls in this article, āgivemeā and āiwanttoknowā.
Remember, this is not a solution! It just plain sucks! I want it to work like in IIS6.However I need it to work right now on IIS7 as well, and fast, so I can finish this app. Iād like to hear if people know how to get it working without the handler and empty files. So leave a comment or contact me if you know.