4
我使用asp.net mvc和下面的代碼來返回異常說明並將其存儲在會話中。我需要幫助找出像500 403 404等異常的錯誤代碼等。我該怎麼做?Asp.Net MVC如何獲取錯誤代碼
這是我如何在會話中存儲錯誤消息。 System.Web.HttpContext.Current.Session [「errorMessage」] = filterContext.Exception.Message.ToString();
public override void OnException(System.Web.Mvc.ExceptionContext filterContext)
{
ProcessResult processResult = new ProcessResult();
//If the exeption is already handled we do nothing
if (filterContext.ExceptionHandled)
{
return;
}
else
{
var controllerName = (string)filterContext.RouteData.Values["controller"];
var actionName = (string)filterContext.RouteData.Values["action"];
var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
processResult.Controller = controllerName;
processResult.Action = actionName;
processResult.ExceptionMessage = filterContext.Exception.Message;
System.Web.HttpContext.Current.Session["errorMessage"] = filterContext.Exception.Message.ToString();
processResult.StackTrace = filterContext.Exception.StackTrace;
processResult.Source = filterContext.Exception.Source;
}
//Mark the exception as handled
filterContext.ExceptionHandled = true;
}
}