8

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
krabcore
  • 885
  • 2
  • 8
  • 22
  • Note that `system.web` applies to ASP.NET only, not ASP.NET Core, and `system.webServer` applies to IIS. None of them is what you should use, like the answer indicated. – Lex Li May 30 '19 at 22:25

5 Answers5

11

web.config

<system.webServer>
    <httpErrors errorMode="Detailed" />
    <aspNetCore processPath="dotnet">
        <environmentVariables>
            <environmentVariable name="ASPNETCORE_DETAILEDERRORS" value="true" />
        </environmentVariables>
    </aspNetCore>
</system.webServer>
Pang
  • 9,564
  • 146
  • 81
  • 122
krabcore
  • 885
  • 2
  • 8
  • 22
  • 1
    An explanation would be in order. E.g., [another answer](https://stackoverflow.com/questions/56380345/how-to-set-the-web-config-file-to-show-the-full-error-message-net-core-2-1/61769129#61769129) claims it doesn't work. Please respond by [editing your answer](https://stackoverflow.com/posts/56473932/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jun 10 '21 at 13:40
8

For me, enabling ASPNETCORE_DETAILEDERRORS didn't do anything, but changing ASPNETCORE_ENVIRONMENT worked:

<environmentVariables>
  <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>

More information: Enable the Developer Exception Page

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Aleh Kliauzo
  • 81
  • 1
  • 2
7

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://learn.microsoft.com/en-us/aspnet/core/fundamentals/error-handling?view=aspnetcore-2.1

Pang
  • 9,564
  • 146
  • 81
  • 122
hujtomi
  • 1,540
  • 2
  • 17
  • 23
  • yeah, I know about it. but I have specific case in which I cant change any .cs files in app. For example you can add "nativeDebugging": true in launchSettings.json and DeveloperExceptionPage will turn on automatically when you debug your app in Visual Studio. Can I somehow turn on this option use only web.config? – krabcore May 31 '19 at 07:58
  • 2
    If you check the link, you'll see that "ASP.NET Core reads the environment variable ASPNETCORE_ENVIRONMENT at app startup" so if you `set ASPNETCORE_ENVIRONMENT=Development` in command line it should work. – hujtomi May 31 '19 at 10:08
1

web.conf

<system.webServer>
  <httpErrors errorMode="Detailed" />
  <aspNetCore processPath="dotnet" arguments=".\DocExpressManager.Web.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
    <environmentVariables>
      <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
      <environmentVariable name="ASPNETCORE_DETAILEDERRORS" value="true" />
    </environmentVariables>
  </aspNetCore>
</system.webServer>
Peter Csala
  • 17,736
  • 16
  • 35
  • 75
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 04 '22 at 06:19
0

I had an issue seeing the yellow screen of death, too. So, instead I sent the output of the exception to a log file by setting stdoutLogEnabled="true" and stdoutLogFile="C:\Users\SomeUser\LoggingDirectory\LogFileName". In this case, you'll get a log file named something like LogFileName_20220607193533_9648.txt.

BE SURE TO RESET IIS.

<configuration>
  <system.web>
    <customErrors mode="Off" />
  </system.web>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\Project.Name.dll" stdoutLogEnabled="true" stdoutLogFile="C:\Users\SomeUser\LoggingDirectory\LogFileName" hostingModel="OutOfProcess" />
    </system.webServer>
  </location>
</configuration>

Disclaimer: I'm not certain that you need the "customErrors mode='Off'" part but, it was there when this solution worked for me.

Tangere Apps
  • 216
  • 4
  • 5