Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting blank pages for error messages with UseDeveloperExceptionPage enabled

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.

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();
        }

My 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"
  ]
}
like image 700
adam3039 Avatar asked Dec 16 '15 05:12

adam3039


People also ask

What is App UseDeveloperExceptionPage?

UseDeveloperExceptionPage(IApplicationBuilder) Captures synchronous and asynchronous Exception instances from the pipeline and generates HTML error responses.

How do you handle exceptions globally in .NET Core?

Use the UseExceptionHandler middleware in ASP.NET Core So, to implement the global exception handler, we can use the benefits of the ASP.NET Core build-in Middleware. A middleware is indicated as a software component inserted into the request processing pipeline which handles the requests and responses.


1 Answers

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

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 however will still show a blank page, as they are not an exception. To configure something else for those, take a look at StatusCodeErrorPages.

like image 169
Stafford Williams Avatar answered Sep 22 '22 07:09

Stafford Williams