I have some basic code to determine errors in my MVC application. Currently In the project I have a controller called Error with action methods "HTTPError404", "HTTPError500", and "General". They all accept a string "error." Using or modifying the code I am working on below, what is the best/proper way to pass the data to the Error controller for processing? I want this solution to be as robust as possible.
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
Response.Clear();
HttpException httpException = exception as HttpException;
if (httpException != null)
{
RouteData routeData = new RouteData();
routeData.Values.Add("controller", "Error");
switch (httpException.GetHttpCode())
{
case 404:
// page not found
routeData.Values.Add("action", "HttpError404");
break;
case 500:
// server error
routeData.Values.Add("action", "HttpError500");
break;
default:
routeData.Values.Add("action", "General");
break;
}
routeData.Values.Add("error", exception);
// clear error on server
Server.ClearError();
// at this point how to properly pass routedata to error controller?
}
}