在启用 UseDeveloperExceptionPage 的情况下获取错误消息的空白页 [英] Getting blank pages for error messages with UseDeveloperExceptionPage enabled

查看:8
本文介绍了在启用 UseDeveloperExceptionPage 的情况下获取错误消息的空白页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我输入无效的 URL 或在我的应用程序中引发异常时,我都会得到空白页.我启用了 UseDeveloperExceptionPage(),并且我确认我的应用程序环境处于开发模式,并且该方法正在触发.该应用程序运行良好,但在浏览器中没有显示错误消息令人沮丧.

I'm getting blank pages for both when I enter an invalid URL, or when an exception is thrown within my application. I have UseDeveloperExceptionPage() enabled, and I have confirmed that my app environment is in development mode, and that the method is firing. The app works fine, but not having error messages displaying in the browser is frustrating.

我的 Startup.cs 配置方法:

My Startup.cs Configure method:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseIISPlatformHandler();
            app.UseStaticFiles();
            app.UseIdentity();
            app.UseMvc(m =>
            m.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" }
                ));

            if(env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            CreateSampleData(app.ApplicationServices).Wait();
        }

我的项目.json

{
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4",
    "Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

推荐答案

顺序很重要 - 将 UseMvc(..) 放在异常块之后,以便异常中间件可以捕获 Mvc 中间件抛出的异常.

The order matters - put UseMvc(..) after your exception blocks so the exception middleware can catch exceptions that the Mvc middleware throws.

如果您查看 DeveloperExceptionPageMiddleware 的源代码,您可以看到它只是在 try/catch 中调用管道中的下一个中间件.

If you take a look at the source for DeveloperExceptionPageMiddleware you can see that it simply calls the next middleware in the pipeline inside a try/catch.

然而,404s 仍然会显示一个空白页面,因为它们也不例外.要为这些配置其他内容,请查看 StatusCodeErrorPages.

404s however will still show a blank page, as they are not an exception. To configure something else for those, take a look at StatusCodeErrorPages.

这篇关于在启用 UseDeveloperExceptionPage 的情况下获取错误消息的空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆