• ExceptionFilter以外的其他异常捕获


    #region 指定错误处理动作
    app.UseStatusCodePagesWithReExecute("/Error/{0}");//只要不是200 都能进来
    app.UseExceptionHandler(errorApp =>
    {
    errorApp.Run(async context =>
    {
    context.Response.StatusCode = 200;
    context.Response.ContentType = "text/html";

    await context.Response.WriteAsync("<html lang="en"><body> ");
    await context.Response.WriteAsync("ERROR!<br><br> ");

    var exceptionHandlerPathFeature =
    context.Features.Get<IExceptionHandlerPathFeature>();

    Console.WriteLine("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
    Console.WriteLine($"{exceptionHandlerPathFeature?.Error.Message}");
    Console.WriteLine("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");

    // Use exceptionHandlerPathFeature to process the exception (for example,
    // logging), but do NOT expose sensitive error information directly to
    // the client.

    if (exceptionHandlerPathFeature?.Error is FileNotFoundException)
    {
    await context.Response.WriteAsync("File error thrown!<br><br> ");
    }

    await context.Response.WriteAsync("<a href="/">Home</a><br> ");
    await context.Response.WriteAsync("</body></html> ");
    await context.Response.WriteAsync(new string(' ', 512)); // IE padding
    });
    });
    app.UseHsts();
    #endregion

  • 相关阅读:
    【宁夏区域赛】G.Pot!
    【C#】上机实验二
    【C#】上机实验三
    Luogu P1437 敲砖块
    Luogu P1463 反素数
    Luogu P1445 樱花
    GHOJ 926 小X的AK计划
    【题解】Beads
    【题解】Antisymmetry
    【题解】A Horrible Poem
  • 原文地址:https://www.cnblogs.com/Robert-huge/p/12870304.html
Copyright © 2020-2023  润新知