Search code examples
iisasp.net-coreasp.net-core-mvciis-10

No detail on error page even if published with Debug configuration


I have an MVC Core application, working perfectly running in debugging mode inside VS and IIS Express. Yet when I publish, under Release config, to IIS 10, an error occurs when I click the Login link. The site displays the utterly useless default error page, the one that comes as part of the VS project template for MVC applications. The only useful information in this page is that there has been an error, and that:

Swapping to Development environment will display more detailed information about the error that occurred.

So I took care to clean out the publish folder, where the website in IIS is pointed to, and published the app again, this time under Debug config.

Yet I still get exactly the same useless error page. Is this a problem with IIS, or am I doing something wrong?


Solution

  • Debug/Release configuration by default has nothing with Development/Production environment. Check this Environments section and Hosting settings to find how to set needed environment. The easiest way is by specifying the ASPNETCORE_ENVIRONMENT env variable.

    Regarding Swapping to Development environment will display more detailed information about the error that occurred.

    This is about WebHostDefaults.DetailedErrorsKey settings:

    When enabled (or when the Environment is set to Development), the app captures detailed exceptions.

    You can explicitly enable it via:

    WebHost.CreateDefaultBuilder(args)
           .UseSetting(WebHostDefaults.DetailedErrorsKey, "true")
    

    There is a good doc section about troubleshooting app deployed on IIS. Among other consider to enable ASP.NET Core Module stdout logs in web.config:

    <aspNetCore processPath="dotnet"
                arguments=".\MyApp.dll"
                stdoutLogEnabled="true"
                stdoutLogFile=".\logs\stdout">
    

    Also for detailed exceptions view you may enable the Developer exception page. Keep in mind that the good practice (for security reason) is to setup this page for Development env only:

    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    

    And the last one in general (butt seems like not your case), you may also catch the startup errors by captureStartupErrors setting:

    WebHost.CreateDefaultBuilder(args)
           .CaptureStartupErrors(true)