.NET CORE中如何过滤异常(简单处理)
2020-12-18 23:33
标签:control filter message content des mes new ext base 在BaseController中 .NET CORE中如何过滤异常(简单处理) 标签:control filter message content des mes new ext base 原文地址:https://www.cnblogs.com/bugenniduobb/p/14131765.html public class ExceptionFilter : IExceptionFilter
{
public void OnException(ExceptionContext context)
{
if (context.ExceptionHandled == false)
{
context.Result = new ContentResult
{
Content = context.Exception.Message,//这里是把异常抛出。也可以不抛出。
StatusCode = StatusCodes.Status500InternalServerError,
ContentType = "text/html;charset=utf-8"
};
}
context.ExceptionHandled = true;
}
}
[TypeFilter(typeof(ExceptionFilter))]
文章标题:.NET CORE中如何过滤异常(简单处理)
文章链接:http://soscw.com/index.php/essay/37194.html