ASP.NET Core应用的错误处理[3]:ExceptionHandlerMiddleware中间件如何呈现“定制化错误页面”

   1: public static class ExceptionHandlerExtensions

   2: {

   3:     public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder app)=> app.UseMiddleware<ExceptionHandlerMiddleware>();

   4:  

   5:     public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder app, ExceptionHandlerOptions options) 

   6:        => app.UseMiddleware<ExceptionHandlerMiddleware>(Options.Create(options));

   7:  

   8:     public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder app, string errorHandlingPath)

   9:     { 

  10:         return app.UseExceptionHandler(new ExceptionHandlerOptions

  11:         {

  12:             ExceptionHandlingPath = new PathString(errorHandlingPath)

  13:         });

  14:     }

  15:  

  16:     public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder app, Action<IApplicationBuilder> configure)

  17:     {

  18:         IApplicationBuilder newBuilder = app.New();

  19:         configure(newBuilder);

  20:  

  21:         return app.UseExceptionHandler(new ExceptionHandlerOptions

  22:         {

  23:             ExceptionHandler = newBuilder.Build()

  24:         });

  25:     }     

  26: }