首页 > Web开发 > 详细

aspnetcore IExceptionFilter

时间:2020-09-16 23:20:30      阅读:86      评论:0      收藏:0      [点我收藏+]
    public class GlobalExceptionFilter : IExceptionFilter
    {
        public void OnException(ExceptionContext context)
        {
            context.Result = new ObjectResult(new { Status = 500, Msg = context.Exception.Message });
        }
    }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddMvc(op =>
            {
                op.Filters.Add(typeof(GlobalExceptionFilter));
            })
            .AddJsonOptions(op =>
            {
                op.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
                op.JsonSerializerOptions.PropertyNamingPolicy = null;// 取消默认首字母大写
            });
        }

 

aspnetcore IExceptionFilter

原文:https://www.cnblogs.com/jonney-wang/p/13681808.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!