asp.net core mvc异常处理

过滤器处理异常

public class GlobalExceptionFilter : IExceptionFilter
{
private ILogger _logger;
public GlobalExceptionFilter(ILogger logger)
{
_logger = logger;
}

    public void OnException(ExceptionContext context)
    {
        var controller = context.ActionDescriptor;
        
        context.ExceptionHandled = true;
        var httpCpde = context.Exception;
        _logger.LogError(new EventId(),context.Exception,null);
        context.Result = new RedirectResult("/home/Page500");
    }
}
posted @ 2022-11-22 22:02  Thinking.N  阅读(33)  评论(0编辑  收藏  举报