简体   繁体   中英

iis 7 dynamic redirects for .html files and directories

I've implemented an httpmodule to manage 301 redirects in the database. It does a simple (cached) db lookup to find any matching entries and if it finds any it performs a redirect.

It works wonderfully for .aspx files and other .Net related extensions.

However, for paths ending in .html or / I'm having a more difficult time. I can add a handler for such files as follows:

<add name="SubDirectory" path="*/*/" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness32" />
  <add name="ForDirectory" path="*/" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness32" />
  <add name="SubHTML" path="*/*.html" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness32" />
  <add name="ForHTML" path="*.html" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness32" />

but I've run into two issues:

  1. If there is a directory with a default document (default.aspx) the ForDirectory handler breaks it.
  2. If anything is requested on these paths that doesn't have a redirect and doesn't exist, the server returns an error rather than a 404: Failed to Execute URL .

Any help would be much appreciated.

Switching IIS to integrated rather than classic mode was/is the solution. No handlers are needed, either.

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