0
我想爲特定的控制器顯示不同的404頁面,然後使用我現在的默認值。我怎樣才能做到這一點?這裏是我的設置現在:ASP.NET MVC和不同控制器的不同404頁面
protected void Application_Error()
{
if (!Request.IsLocal)
{
var context = new HttpContextWrapper(HttpContext.Current);
if (!context.Request.IsAjaxRequest())
{
context.Response.ContentType = "text/html";
var unhandledException = Server.GetLastError();
var httpException = unhandledException as HttpException;
if (httpException == null)
{
var innerException = unhandledException.InnerException;
httpException = innerException as HttpException;
}
Server.ClearError();
var routeData = new RouteData();
routeData.Values.Add("controller", MVC.Errors.Name);
if (httpException != null)
{
var httpCode = httpException.GetHttpCode();
switch (httpCode)
{
case (int) HttpStatusCode.NotFound:
routeData.Values.Add("action", "PageNotFound");
IController pageNotFoundController = new ErrorsController();
pageNotFoundController.Execute(new RequestContext(context, routeData));
break;
}
}
else
{
routeData.Values.Add("exception", unhandledException);
routeData.Values.Add("action", "Error");
IController errorController = new ErrorsController();
errorController.Execute(new RequestContext(context, routeData));
}
}
}
}
看看這些現有[http://stackoverflow.com/questions/619895/how-can-i-properly-handle-404-in-asp-net-mvc](http://stackoverflow.com/questions/619895/how-can-i-properly-handle-404-in-asp-net-mvc)回答 – TugboatCaptain