views:

2042

answers:

5

I've got a website running under ASP .NET 2/IIS7/Vista. I have a URL rewriting module which allows me to have extensionless URLs. To get this to work I have configured the system.webServer section of the config file such that all requests are forwarded to the aspnet_isapi.dll. I have also added the URL rewrite module to the modules section and set runAllManagedModulesForAllRequests to true.

When I start up the website and visit one of the pages that uses the URL rewriting, the page is rendered correctly. However if I then visit another page the site stops working and I get a 404 not found. I also find that my breakpoint in the URL rewriting module is not getting hit. It's almost as if IIS forwards the first request to the rewriter, but subsequent ones go somewhere else - the error page mentions Notification as being MapRequestHandler and Handler as being StaticFile.

If I then make a small change to the web.config file and save it, triggering the website to restart, I can then reload the page in the browser and it all works. Then I click another link and it's broken again.

For the record, here's a couple of snippets from the config file. First, under system.web:

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

and then, under 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 is running under classic rather than integrated pipeline mode.

Does anyone out there have any ideas? I suspect my configuration is wrong somewhere but I can't seem to find where.

A: 

This is a bit of a long shot, but have you tried actually making the configuration changes inside of IIS?

I know that the web.config way is supposed to be 100% foolproof, but I've seen a few things where it helps to just configure it in IIS to get it working correctly.

Mitchel Sellers
I've tried this but to no avail.
gilles27
Interesting, do you have anything else that modifies the config? Or any other global handlers registered? Is this application a virtual directory?
Mitchel Sellers
AFAIK, nothing else modifies the config. The code is running a website rather than virtual directory. I've added some samples of the config to the question itself.
gilles27
I have had trouble getting wild card support to work right in IIS 7.0. You may want to try adding a <remove /> right before your handler that you added in to make sure that nothing else is trying to run before you stuff.
Nick Berardi
A: 

You also may want to check out the new IIS7 rewrite module. you can read more about it here http://learn.iis.net/page.aspx/460/using-url-rewrite-module/, but chances are it will be more solid then your homegrown ISAPI filter

Matt Briggs
Thanks but I need my own rewriter as our rewriting is quite custom. I'm also pretty confident the rewriting is working fine, it's just that static file requests are not working properly.
gilles27
A: 

Try http://www.codeplex.com/urlrewriter it supports all the Apache mod_rewrite syntax and also supports Reverse Proxy.

Nick Berardi
Thanks but I need my own rewriter as our rewriting is quite custom. I'm also pretty confident the rewriting is working fine, it's just that static file requests are not working properly.
gilles27
A: 
  1. If you're runnning in classic pipeline mode you don't need <system.webServer> section it is required for integrated mode
  2. Enable wildcard script mapping

    1. Open the IIS7 Manager and navigate to your site

    2. Click on Handler Mappings

    3. In the Action panel click on "Add Wild Card Script Map"

    4. In the dialog point to aspnet_isapi.dll

    5. Click Yes on the message box that asks you to confirm your mapping

    6. In the action panel click on "View Ordered List" and move your WildcardScriptMap just before StaticFile Handler

This should bee enough.

I've tried this and I still get the same issue. I also noticed that, after using IIS to make the changes you suggested, if I go back into Visual Studio there is a new <system.webServer> section in the config file.
gilles27
A: 

I'm ashamed to admit this but it was a simple mistake by me :-(

In my URL rewriting module, the code to rewrite the request path was in the Init method, when it should have been inside an Application.BeginRequest handler. This explains why the rewriting worked only the first time the site was hit.

Sorry to have wasted your time people!

gilles27