zoukankan      html  css  js  c++  java
  • DotNETCore 学习笔记 异常处理

    Error Handling
    
    public void Configure(IApplicationBuilder app, 
        IHostingEnvironment env)
    {
        app.UseIISPlatformHandler();
    
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
    
    
    public static void HomePage(IApplicationBuilder app)
    {
        app.Run(async (context) =>
        {
            if (context.Request.Query.ContainsKey("throw"))
            {
                throw new Exception("Exception triggered!");
            }
            var builder = new StringBuilder();
            builder.AppendLine("<html><body>Hello World!");
            builder.AppendLine("<ul>");
            builder.AppendLine("<li><a href="/?throw=true">Throw Exception</a></li>");
            builder.AppendLine("<li><a href="/missingpage">Missing Page</a></li>");
            builder.AppendLine("</ul>");
            builder.AppendLine("</body></html>");
    
            context.Response.ContentType = "text/html";
            await context.Response.WriteAsync(builder.ToString());
        });
    }
    
    
    app.UseExceptionHandler("/Error");
    [Route("/Error")]
    public IActionResult Index()
    {
        // Handle error here
    }
    
    Configuring Status Code Pages
    app.UseStatusCodePages();
    app.UseStatusCodePages(context =>
      context.HttpContext.Response.SendAsync("Handler, status code: " +
      context.HttpContext.Response.StatusCode, "text/plain"));
    
    app.UseStatusCodePages("text/plain", "Response, status code: {0}");
    
    app.UseStatusCodePagesWithRedirects("~/errors/{0}");
    app.UseStatusCodePagesWithReExecute("/errors/{0}");
    
    If you need to disable status code pages for certain requests, you can do so using the following code:
    var statusCodePagesFeature = context.Features.Get<IStatusCodePagesFeature>();
    if (statusCodePagesFeature != null)
    {
      statusCodePagesFeature.Enabled = false;
    }
  • 相关阅读:
    Moonlight, 我看行。
    传授犯罪方法罪
    Archos TV+ 1.8.07 照样“越狱”
    写这个月的回忆记,还真少不了学车那点儿事儿
    trigger()与triggerHandler()的不同
    移除不同的
    jq中的效果
    jquery中的文档操作之一addClass append attr
    jquery中的文档操作之四
    toggle方法
  • 原文地址:https://www.cnblogs.com/ziranquliu/p/5871216.html
Copyright © 2011-2022 走看看