我对Web应用程序有以下要求,包括MVC 5页面和WebApi 2服务:
所有错误(404,500,“从客户端检测到潜在危险的Request.Form值”)应该生成相应的错误页面(没有浏览器重定向,保留用户在地址栏中输入的URL )。
所有错误页面都应使用动态MVC视图呈现,并包含用户可以为电话支持提供的唯一ID。
必须记录所有错误,日志条目应包含为用户提供的ID。
针对不同的例外情况生成不同的错误页面,例如/error/NoSignal
代表NoSignalException。
这可行吗?
答案 0 :(得分:1)
我会覆盖异常挂起方法 - 在每个控制器或基础中(取决于您的决定)。
protected override void OnException(ExceptionContext filterContext)
{
filterContext.Exception.ToString(); // - make any checks here
// If method is not implemented
if (filterContext.Exception.GetType() == typeof(NotImplementedException))
{
filterContext.Result = new ViewResult { ViewName = "NotImplemented" };
filterContext.ExceptionHandled = true;
}
}