0

Short Version
Please read at the very bottom for a short version of the question.

Situation
In a question I asked last week, I struggled in finding a solution, which makes our asp.net error visualization waterproof, since there are some edge cases where the asp.net exception handling fails and hence no proper exception visualizations can be created:
How to properly set up ASP.NET web.config to show application specific, safe and user friendly asp.net error messages in edge cases

Desired Solution
As an alternative to the way I described there, in my opinion the best way to make the exception visualization reliable, would be to use the httpErrors-element in system.webServer as a failsave so that any error which is not properly handled by asp.net, leads to a generic error page which is shown based on the settings of the httpErrors-element .

To accomplish this, there must be two things possible:

  • Error pages properly handled by the application must pass through iis without being replaced with a generic error message
  • Errors which could not be processed properly in asp.net, must be replaced through IIS.

It is my understanding, that this very behaviour is meant by the existingResponse="Auto" parameter in the httpErrors-element.
The ms documentation states:

Leaves the response untouched only if the SetStatus flag is set.

This is exactly what is necessary: Any successful error page creation in the application (through Application_Error or through an explicitly defined error handling page) can set Response.TrySkipIisCustomErrors = true and IIS would let the error page pass through. However, every other error which was not successfully handled by the application in asp.net, would not set the flag and hence get the error page which is specified in the httpErrors-element.

The Problem
Sadly, it seems that in MVC5-applications (I don’t known whether the same behavior is true in other environments), the Response.TrySkipIisCustomErrors (fTrySkipCustomErrors) seems to be set automatically to [true], even if it is not set by the application.

Hence we are at the same place, as in my other post: If the error handling of the application blows, there is no way to show an application specific error with existingResponse="Auto", since its not possible to reset the fTrySkipCustomErrors flag.
As an alternative, one can set existingResponse="PassThrough". That's what we do currently, since we want to generate our error pages with a support-code and other helpfull information about the error to be shown to the user, or one can use existingResponse="Replace", but this is not an option, since it replaces any error page so that we don’t can show the user any error-specific information such as the support-code mentionen before.

Quesition in Short
The question is therefore, how to make sure that MVC5 (asp.net) does not set the fTrySkipCustomErrors flag automatically to [true], since there are situations, where no application code is executed and hence the Response.TrySkipIisCustomErrors (fTrySkipCustomErrors) cannot be set to false, what renders the existingResponse="Auto" parameter moot.

To check such a situation where the asp.net MVC5 exception handling blows but the fTrySkipCustomErrors flag is set to true, please request the following page from your MVC5 application:

http[s]://[yourWebsite]/com1

Please note: I'm not interested in disabling the above error. It's an example. I want the error visualization reliable and not to have to circumvent every error that possibly can blow asp.net's error handling mechanisms.

HCL
  • 36,053
  • 27
  • 163
  • 213
  • Is your IIS App Pool set correctly? According to the docs (https://learn.microsoft.com/en-us/dotnet/api/system.web.httpresponse.tryskipiiscustomerrors?view=netframework-4.7.2), this is set to true only in the classic pipeline, not when running integrated. *When running in Classic mode, the TrySkipIisCustomErrors property default value is true. When running in Integrated mode, the TrySkipIisCustomErrors property default value is false.* – Tommy Mar 29 '21 at 10:37
  • Hi, thanks, but no, all webs run in in the integrated pipeline. I suspect, that asp.net sets the TrySkipIisCustomErrors to true, before the custom error handling has been processed. And since the application was not hit, it cannot undo this false assignment. – HCL Mar 29 '21 at 15:21

0 Answers0