zoukankan      html  css  js  c++  java
  • aspnetcore IExceptionFilter

        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;// 取消默认首字母大写
                });
            }
  • 相关阅读:
    第三章例3-3
    第三章例3-2
    第二章例2-11
    第二章例2-10
    第二章例2-9
    204
    205
    202
    203
    201
  • 原文地址:https://www.cnblogs.com/jonney-wang/p/13681808.html
Copyright © 2011-2022 走看看