Created
July 30, 2014 03:09
-
-
Save imwower/b7c3a3b03d2f790e3495 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MvcErrorAttribute : HandleErrorAttribute | |
{ | |
public ILogger Logger { get; set; } | |
public ErrorController ErrorController { get; set; } | |
public MvcErrorAttribute() | |
{ } | |
public override void OnException(ExceptionContext filterContext) | |
{ | |
if (filterContext.ExceptionHandled) | |
return; | |
filterContext.ExceptionHandled = true; | |
var exception = filterContext.Exception; | |
string controllername = filterContext.RouteData.Values["controller"] as string; | |
string actionname = filterContext.RouteData.Values["action"] as string; | |
Logger.Error(string.Format("error on filter context, controller : {0}, action : {1}", controllername, actionname), exception); | |
var routeData = new RouteData(); | |
routeData.Values["controller"] = "Error"; | |
routeData.Values["action"] = "Error"; | |
var httpexception = exception as HttpException; | |
if (httpexception != null) | |
routeData.Values["code"] = httpexception.GetHttpCode(); | |
var url = "http://localhot:8080/Error/Error"; //the urL of Error Controller | |
var str = "<script>location.href='" + url + "'</script>"; | |
HttpContext.Current.ClearError(); | |
HttpContext.Current.Response.Clear(); | |
HttpContext.Current.Response.Write(str); | |
HttpContext.Current.Response.End(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment