Problems rewriting URLs using ASP.NET 2 on IIS7 and Vista

I have a site running ASP.NET 2 / IIS7 / Vista. I have a URL rewrite module that allows me to have URLs without extension. To make this work, I configured the system.webServer section of the configuration file so that all requests are forwarded to aspnet_isapi.dll. I also added a URL rewrite module to the modules section and set runAllManagedModulesForAllRequests to true.

When I launch a website and visit one of the pages using URL rewriting, the page displays correctly. However, if I then go to another page, the site will stop working, and I will not find 404. I also found that my breakpoint in the URL rewrite module did not hit. It is almost the same as if IIS redirects the first request to the rewriting device, but the subsequent ones are sent to another place - on the error page the notification is mentioned as MapRequestHandler and the handler as StaticFile.

If I then make a small change to the web.config file and save it, triggering a reload of the website, I can reload the page in the browser and it will all work. Then I click another link and it breaks again.

To write here, a couple of fragments from the configuration file. Firstly, in system.web:

<httpModules> <add name="UrlRewriteModule" type="Arcs.CoopFurniture.TelesalesWeb.UrlRewriteModule, Arcs.CoopFurniture.TelesalesWeb" /> </httpModules> 

and then in system.webServer:

 <system.webServer> <modules runAllManagedModulesForAllRequests="true"> <add name="UrlRewriteModule" type="Arcs.CoopFurniture.TelesalesWeb.UrlRewriteModule, Arcs.CoopFurniture.TelesalesWeb" preCondition="managedHandler" /> </modules> <handlers> <add name="AspNet" path="*" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" preCondition="classicMode,runtimeVersionv2.0,bitness32" /> </handlers> <validation validateIntegratedModeConfiguration="false" /> </system.web> 

The site operates in a classic, rather than an integrated pipeline mode.

Does anyone have any ideas? I suspect that my configuration is somewhere wrong, but I cannot find where.

+3
source share
5 answers

I am ashamed to admit it, but it was a simple mistake: - (

In my URL rewrite module, the code to rewrite the request path was in the Init method when it was supposed to be inside the Application.BeginRequest handler. This explains why rewriting only worked on the first hit of the site.

Sorry to waste your time on people!

0
source

This is a bit long shot, but have you tried to make configuration changes inside IIS?

I know that the web.config method should be 100% reliable, but I have seen a few things where it helps just configure it in IIS so that it works correctly.

0
source

You can also check out the new IIS7 rewriting module. you can read about it here http://learn.iis.net/page.aspx/460/using-url-rewrite-module/ , but most likely it will be more durable than your home ISAPI filter resource.

0
source

Try http://www.codeplex.com/urlrewriter , it supports all Apache mod_rewrite syntax and also supports reverse proxy.

0
source
  • If you are working in classic pipeline mode, you do not need the <system.webServer> section, which is required for the built-in mode
  • Enable wildcard matching script

    • Open IIS7 Manager and go to your website

    • Click "Handler Mappings"

    • In the action bar, click "Add Wild Card script Map"

    • In the dialog box to aspnet_isapi.dll

    • Click "Yes" in the message box, in which you will be asked to confirm your association

    • In the action pane, click View Ordered List and move your wildcard template directly in front of the StaticFile handler

That should be enough.

0
source