简体   繁体   中英

URL rewriting problems with ASP .NET 2 on IIS7 and Vista

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.

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.

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

尝试http://www.codeplex.com/urlrewriter它支持所有Apache mod_rewrite语法,并且还支持反向代理。

  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'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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM