Share via


How to Enable Wildcard Script Mapping in IIS7.5 Integrated Pipeline to Customize 404 Error page

The problem happens when we navigate to a URL that does NOT contain a .NET extension – https://localhost/Test/vanityUrl. If the URL was to end in page *.aspx then the custom error handling would redirects to the customized 404 page as expected.

However, if the URL is like https://localhost/Test/ or https://localhost/Test/test.123, the default “404” error would be returned:

clip_image002

Now the question is how to make sure the customized 404 page being returned even for extension-less or non-dotnet extensions.

Server Environment: Windows Server 2008 R2 (64bit)

IIS Version: 7.5

Application Framework: .NET v2.0

Application Pool Mode: Integrated

As we know, this is not a problem in IIS6 or if we set the site running in Classic mode in IIS7.5. Previously in IIS 6 the handling of extension-less or non-dotnet extensions was handled by a wildcard ISAPI extension. Switch the site to run in Classic mode also results in the expected behavior. For detailed information, please reference the below article:

Wildcard script mapping and IIS 7 integrated pipeline

How to achieve the same target in IIS7.5 Integrated pipeline?

You might want to try “Error Pages” feature in IIS Manager but it doesn’t work as expected:

clip_image004

The same default “404” error would be returned:

clip_image005

After several rounds of test, I found that we can use the below way to Enable Wildcard Script Mapping in IIS7.5 Integrated Pipeline to Customize 404 Error page:

Add the below lines to the web.config of the related website in “Handler Mapping” section:

<add name="PageHandlerFactory-Integrated-wildcard2" path="*" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.PageHandlerFactory" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="integratedMode" responseBufferLimit="4194304" />

The above line is actually copied from the below handler mapping directly and I just change the path from “*.aspx” to “*”:

<add name="PageHandlerFactory-Integrated" path="*.aspx" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.PageHandlerFactory" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="integratedMode" responseBufferLimit="4194304" />

Once the above handler being added in web.config manually, you can check it in “Handler Mappings” directly:

clip_image007

After I applied the above change, the extension less URL could be redirected to customized 404 aspx as expected:

clip_image009

clip_image011

NOTE: To make the above customized “404” error page being redirected, still you need to add the below lines in web.config of the related website:

<httpErrors>

<remove statusCode="404" subStatusCode="-1" />

<error statusCode="404" prefixLanguageFilePath="" path="/ERROR/404.ASPX" responseMode="ExecuteURL" />

</httpErrors>

Regards,

Yong Kang Chen from GBSD DSI Team

Comments

  • Anonymous
    June 26, 2016
    A very detailed Post.Came handly to me. Thanks.