Skip to content

Instantly share code, notes, and snippets.

@alanwei43
Last active July 9, 2018 09:01
Show Gist options
  • Save alanwei43/af6944c262562d08c72e1dd00a28699a to your computer and use it in GitHub Desktop.
Save alanwei43/af6944c262562d08c72e1dd00a28699a to your computer and use it in GitHub Desktop.
ASP.Net 全局异常处理
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