Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Reach the Custom Errors page in ASP.NET when Session State Provider is Down?

I am trying to show a customer errors page in ASP.NET when the database is down. I use the SQL Server mode to hold the session data. The problem is that the custom errors page is never called.

Since the session data and the database are on the same server, this does not redirect to the custom error page? I’m guessing the web application has not loaded at this point?. The user is presented with the stack trace for the session state connection failure.

It seems that we need something that sits in front of the initial website load to check connectivity to the database. Any ideas on how to implement this?

like image 956
GoldenUser Avatar asked Jun 23 '11 18:06

GoldenUser


People also ask

How does ASP.NET handle custom errors?

In ASP.Net, error can be handled programmatically by writing appropriate code in the page-level error event, for errors on an individual page or in the application-level error event for handling errors that may occur in any page of the application.

What happens when custom errors are on but no default redirect path is specified?

If no defaultRedirect is specified, users see a generic error page e.g. Error. cshtml in ASP.NET MVC application. Off: Specifies that custom errors are disabled. This displays detailed errors.

Which of the following tags should be used to define the error page that is to be shown within Web config?

To display a custom error page with an appropriate error code, use the <httpErrors> section only, and do not use the <customErrors> section.


2 Answers

Add something like this to your web.config?

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
    <error statusCode="403" redirect="NoAccess.htm" />
    <error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>

You can read more information here

If it is your SqlSessionState that is failing, you should handle the corresponding error in the Application_Error event in Global.asax

You can read more information here

like image 84
FlyingStreudel Avatar answered Nov 15 '22 01:11

FlyingStreudel


I believe the error is coming from the fact that because you're using an out of memory session state provider (being the database), and the database connection has a failure, then there is actually a perceived error in the web configuration (not in the application). I have a similar problem, where I'm using AppFabric Cache for my session state provider, but when the AppFabric Cache Service is down, I get the Configuration Error page.

Because of this, you can't use the customErrors solution as FlyingStreudel has already suggested, since it isn't an error in your application, but rather in the loading of the configuration.

I've looked around for a way to solve this, but couldn't find any. I hope this question gets answered, it's got me confused already with the various error configuration options...

Update: After investigating this for a while now, it appears that my issue comes from the fact that the SessionStateModule causes the AppFabric cache session state provider to try and connect to the DataCache (which is not available), and an exception (probably timeout) is thrown somewhere. Because this happens in the Init of the HTTP module, there seems to be no way around the yellow screen of death.

I wouldn't be surprised if the original poster's problem is the same - the connection to the SQL server occurring in the initialization of the SessionStateModule.

like image 43
jamiebarrow Avatar answered Nov 15 '22 00:11

jamiebarrow