I know that ASP.NET MVC has error filter attribute to handle specified error type. However, this feature cannot catch any error that occurs when application start. Therefore
The reason why Request
and Response
objects are null
inside your Application_Error
event is because the Application_Start
event is not associated with any user, therefore you cannot redirect from it. Only the Application
and Server
built-in objects are available. Referencing the Session
, Request
, or Response
objects would cause an error.
One workaround is to use try/catch
and in the catch
block log the error and set some global variable which indicates that something went wrong during application startup. Later on Application_BeginRequest
you could check this variable and redirect accordingly.