Last active
July 9, 2018 09:01
-
-
Save alanwei43/af6944c262562d08c72e1dd00a28699a to your computer and use it in GitHub Desktop.
ASP.Net 全局异常处理
This file contains hidden or 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 GlobalErrorActionFilter : IExceptionFilter | |
{ | |
public void OnException(ExceptionContext filterContext) | |
{ | |
Exception ex = filterContext.Exception; | |
filterContext.ExceptionHandled = true; | |
var response = filterContext.HttpContext.Response; | |
response.Clear(); | |
response.StatusCode = 200; | |
response.TrySkipIisCustomErrors = true; | |
ContentResult result = new ContentResult(); | |
result.Content = "some text"; | |
filterContext.Result = result; | |
} | |
} | |
/* | |
* GlobalFilters.Filters.Add(new GlobalErrorActionFilter()); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ASP.net MVC - Custom HandleError Filter - Specify View based on Exception Type