0
我有以下對一個ASP.NET MVC應用5處理錯誤:無法處理ASP.NET MVC上的404錯誤。爲什麼?
protected void Application_Error() {
var exception = Server.GetLastError();
var httpException = exception as HttpException;
Response.Clear();
Server.ClearError();
var routeData = new RouteData();
routeData.Values["controller"] = "Errors";
routeData.Values["action"] = "Internal";
routeData.Values["exception"] = exception;
Response.StatusCode = 500;
if (httpException != null) {
Response.StatusCode = httpException.GetHttpCode();
switch (Response.StatusCode) {
case 403:
routeData.Values["action"] = "Forbidden";
break;
case 404:
routeData.Values["action"] = "NotFound";
break;
}
}
// Avoid IIS7 getting in the middle
Response.TrySkipIisCustomErrors = true;
IController errorsController = new ErrorController();
HttpContextWrapper wrapper = new HttpContextWrapper(Context);
var rc = new RequestContext(wrapper, routeData);
errorsController.Execute(rc);
}
這工作得很好,但是當我輸入,在地址欄中,一所沒有的URL我沒有得到404錯誤。
我什麼都試過了我能想到的,但沒有運氣...
任何想法,爲什麼?
謝謝你,
米格爾