In my Global.asax I have defined the Application_error method :
protected void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
// Get the exception object.
var exc = Server.GetLastError();
//logics
Response.Redirect(String.Format("~/ControllerName/MethodName?errorType={0}", errorAsInteger));
}
And the exc variable does keep the last error but After being redirected from the response in the responding method(MethodName) the Server.GetLastError()
is null. How can I keep it or pass it to the Response.Redirect(String.Format("~/ControllerName/MethodName?errorType={0}"
so I can have the exception in my method body as an object ?
I would like to advise you to not redirect when there is an error so that the URL is preserved and the correct HTTP status code is set.
Instead, execute your controller inside
Application_Error
Then ErrorController is