0

My asp.net 5 application is throwing a blank html page at me, if an exception occurs. My goal is to display the default error page.

This question and this question seem to be related, but it is seems to be outdated, since we don't have a web.config any longer and the second one doesnt solve my problem.

This is my Configure() method in the startup.cs:

public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env)
{
    loggerFactory.AddDebug(LogLevel.Warning);

    app.UseStaticFiles();
    app.UseMvc(config =>
    {
        //[...]
    });

    if (env.IsDevelopment())
    {
        app.UseBrowserLink();
        loggerFactory.AddDebug(LogLevel.Information);
        app.UseDeveloperExceptionPage();
    }
    else
    {
        loggerFactory.AddDebug(LogLevel.Debug);
        app.UseDeveloperExceptionPage();
    }
    //[...]
}

I have confirmed, that the code is actually hitting the if condition and the UserDeveloperExceptionPage method is loaded, but to no avail.

What am I missing?

Community
  • 1
  • 1
Marco
  • 22,856
  • 9
  • 75
  • 124
  • 2
    You may not be using a web.config in your application, but you can still use them, as well as other configuration files. Take a look at the cloud-ready configuration section in this article: http://weblogs.asp.net/scottgu/introducing-asp-net-5. Also, take a look at this question, seems related to your issue: http://stackoverflow.com/questions/34304575/getting-blank-pages-for-error-messages-with-usedeveloperexceptionpage-enabled – Jerreck Feb 14 '16 at 20:10
  • Yep, this is actually a duplicate. – Marco Feb 14 '16 at 20:14

1 Answers1

1

Ok I found a solution

Order matters. You need to instantiate the error handling middleware before the MVC middleware. Otherwise, there will be just no exception handling.

Putting the error handling configuration just before the app.UseMvc(x => {...}) does the trick:

if (env.IsDevelopment())
{
    app.UseBrowserLink();
    loggerFactory.AddDebug(LogLevel.Information);
    app.UseDeveloperExceptionPage();
}

app.UseMvc(config =>
{
    //[...]
});

Simple as that.

Marco
  • 22,856
  • 9
  • 75
  • 124