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 ?
The value of TempData persists until it is read or until the session times out. Persisting TempData in this way enables scenarios such as redirection, because the values in TempData are available beyond a single request.
Then in your action you can use
But here is other solution which you can do without redirect
then in Controller you can add action