Ugur
Ugur

Reputation: 156

ExtensionlessUrlHandler causes 404 Not Found with default document on IIS

I recently updated some ASP.NET Nuget packages and modified the index.html file of my web site. Now I get 404-Not Found error but ONLY for the root path, i.e. when the web site address is typed without subdirectory or file name.

If I explicitly append "/index.html" then the default document is displayed correctly.

I also noticed that the line below in my web.config file has an unexpected behavior: If I remove the line, then the root path can be displayed, but the Web API requests return 404-Not Found response. If I keep it, then Web API requests work but the default document causes 404-Not Found.

<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

The complete "handlers" section of web.config is as follows:

<handlers>
    <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
    <remove name="OPTIONSVerbHandler" />
    <remove name="TRACEVerbHandler" />
    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

I made no changes to the default document setting or physical path file permissions. How can I fix this?

Upvotes: 1

Views: 1050

Answers (1)

Ugur
Ugur

Reputation: 156

I just discovered that the problem has nothing to do with my modification in index.html. The actual cause originated from the way MVC routing works: I had just added MVC components to my project, and newly-added MVC route config started digesting all extensionless paths. As per this explanation, I just added an exception for the root path (the empty string), and the problem was fixed:

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.MapMvcAttributeRoutes();
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("");

        ...
    }
}

Upvotes: 1

Related Questions