当我输入无效的URL或者在我的应用程序中抛出异常时,我得到空白页面.我启用了UseDeveloperExceptionPage(),并且我已确认我的应用程序环境处于开发模式,并且该方法正在触发.该应用程序工作正常,但没有在浏览器中显示错误消息令人沮丧.
我的Startup.cs配置方法:
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(); }
我的project.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" ] }
Stafford Wil.. 13
顺序很重要 - 放在UseMvc(..)
异常块之后,因此异常中间件可以捕获Mvc中间件抛出的异常.
如果您查看源代码,DeveloperExceptionPageMiddleware
您可以看到它只是在try/catch中调用管道中的下一个中间件.
然而,404s仍将显示空白页面,因为它们不是例外.要为这些配置其他内容,请查看StatusCodeErrorPages.
顺序很重要 - 放在UseMvc(..)
异常块之后,因此异常中间件可以捕获Mvc中间件抛出的异常.
如果您查看源代码,DeveloperExceptionPageMiddleware
您可以看到它只是在try/catch中调用管道中的下一个中间件.
然而,404s仍将显示空白页面,因为它们不是例外.要为这些配置其他内容,请查看StatusCodeErrorPages.