Reputation: 407
I have the following requirements for a web app, that consist of MVC 5 pages and WebApi 2 services:
All errors (404, 500, "A potentially dangerous Request.Form value was detected from the client") should produce corresponding error pages in place (no browser redirect, keep the URL the user entered in the address bar).
All error pages should be rendered using dynamic MVC views and contain a unique ID, that the user can give to phone support.
All errors must be logged, the log entries should contain the Id given to the user.
Produce different error pages for different exceptions, e.g. /error/NoSignal
for NoSignalException.
Is this doable?
Upvotes: 0
Views: 153
Reputation: 2797
I would override exception hangling method - in each controller or in base (depends on your decision).
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;
}
}
Upvotes: 1