Tuesday, February 23, 2016

MVC error on IIS 7 and 7.5 The Web server is configured to not list the contents of this directory.

If you get the error:The Web server is configured to not list the contents of this directory.

It is because the MVC URLs end without .aspx, these will not be picked up by IIS and run through the intergrated pipeline and therefore you will end up with 404 not found errors.
Another possible cause is you are using a .Net 4.5 application on a server where it was installed after IIS.

To solve this problem consider how much traffic you will have on your site, if you are not going to have a lot of traffic use the attribute runAllManagedModulesForAllRequest with true value, but keep in mind all your registered HTTP modules run on every request, not just managed requests (e.g. .aspx). This means modules will run on ever .jpg .gif .css .html .pdf etc.

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

But if you are going to have a lot of traffic it is better to add the routing module:

<system.webServer>
    <modules>
      <remove name="UrlRoutingModule-4.0" />
      <add name="UrlRoutingModule-4.0" 
           type="System.Web.Routing.UrlRoutingModule" 
            preCondition="" />
    </modules>
  </system.webServer>

Another solution is to install a patch from Microsoft that enables certain IIS 7.0 or IIS 7.5 handlers to handle requests whose URLs do not end with a period.
This is the link to download this patch:

https://support.microsoft.com/en-us/kb/980368