Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the 'web.config' file to show the full error message (.NET Core 2.1)

I hosted my ASP.NET Core app on IIS (using the publish-in- folder method). I tried to create my own web.config file to see detailed error messages on the client side. So I added file web.config:

<configuration>
    <system.web>
        <customErrors mode="Off" />
    </system.web>
    <system.webServer>
        <httpErrors errorMode="Detailed" />
    </system.webServer>
</configuration>

After I restarted IIS, nothing happened. Clients still got the default error:

Enter image description here

Can I somehow get additional information about errors using file web.config?

like image 424
krabcore Avatar asked May 30 '19 14:05

krabcore


2 Answers

web.config

<system.webServer>
    <httpErrors errorMode="Detailed" />
    <aspNetCore processPath="dotnet">
        <environmentVariables>
            <environmentVariable name="ASPNETCORE_DETAILEDERRORS" value="true" />
        </environmentVariables>
    </aspNetCore>
</system.webServer>
like image 55
krabcore Avatar answered Sep 22 '22 06:09

krabcore


You can configure it in your Startup.cs file. By default, it shows the Developer Exception Page only in development mode:

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

If you replace this part just with app.UseDeveloperExceptionPage(); it will always show the detailed error message.

You can read more about it here: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/error-handling?view=aspnetcore-2.1

like image 34
hujtomi Avatar answered Sep 20 '22 06:09

hujtomi