首页 > Web开发 > 详细

aspnetcore IExceptionFilter

时间:2020-09-16 23:20:30      阅读:23      评论:0      收藏:0      [点我收藏+]

标签:ont   void   contex   大写   json   sage   

    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

标签:ont   void   contex   大写   json   sage   

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

(0)
(0)
   
举报
评论 一句话评论(0
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号