【发布时间】:2018-03-07 05:24:17
【问题描述】:
我正在尝试处理 MVC 中的 404 错误,所有其他错误正在使用 Angular 进行处理,因此不必担心其他异常。
我正在像这样处理 Global.asax 页面中的 404 错误
protected void Application_Error()
{
// if (Context.IsCustomErrorEnabled)
ShowCustomErrorPage(Server.GetLastError());
}
private void ShowCustomErrorPage(Exception exception)
{
var httpException = exception as HttpException ?? new HttpException(500, "Internal Server Error", exception);
Response.Clear();
var routeData = new RouteData();
routeData.Values.Add("controller", "ErrorHandling");
routeData.Values.Add("fromAppErrorEvent", true);
switch (httpException.GetHttpCode())
{
case 404:
routeData.Values.Add("action", "HttpError404");
break;
}
Server.ClearError();
IController controller = new ErrorHandlingController();
controller.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
}
但是当 404 错误发生时 Execute 方法
controller.Execute(new RequestContext(new HttpContextWrapper(Context), 路由数据));
呈现页面的 html 而不是页面本身,如何进行更改以便我能够呈现页面本身而不是页面的 html。
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-4 c#-4.0 error-handling