2

I have asp.net mvc 4 site hosted in IIS 7.5. I'm handling all the http errors manually in the Application_Error handler. Everything is fine except the 403 error(for example when navigating to the http://mysite/App_Data). The problem is that the Application_Error doesn't catch this error. Could someone tell me how to get it working?

EDIT

I found out that the Application_Error catches only exceptions thrown in the managed modules. Since 403 error (in my case it's 403.14) is thrown by the DirectoryListingModule which is unmanaged, this error cannot be caught by the Application_Error. Also, it might be 404.7 or 404.8 errors handled by the RequestFilteringModule(also unmanaged). The only way I found to customize the handling of these errors is to use the following settings:

  <httpErrors errorMode="Custom" existingResponse="Replace">
      <error path="/Error/Forbidden" statusCode="403" subStatusCode="14" responseMode="ExecuteURL"/>
      <error path="/Error/NotFound" statusCode="404" subStatusCode="7" responseMode="ExecuteURL"/>
      <error path="/Error/NotFound" statusCode="404" subStatusCode="8" responseMode="ExecuteURL"/>
  </httpErrors>

having the ErrorController with the NotFound action. But there is one drawback with this approach for me - the original request data that causes the error is lost(because a child server-side redirect is performed) and I have no way to get it(at least I don't know how). So, now I'd like to change my question: Is it the only way to handle such errors ? And are there ways to get the original request data when using the httpErrors approach?

andrew
  • 1,030
  • 2
  • 8
  • 21

1 Answers1

0

Set runAllManagedModulesForAllRequests to true in web.config in modules under system.webServer.

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    ...
</system.webServer>
Ε Г И І И О
  • 11,199
  • 1
  • 48
  • 63