How to Debug and View Detailed ASP.NET 500 Internal Server Errors in IIS


1 views

When deploying an ASP.NET Web API to IIS, encountering a generic 500 Internal Server Error without detailed error information is a common frustration. The error page typically shows just "500 - Internal server error" without revealing the root cause, making debugging challenging.

To get more meaningful error messages, you need to configure IIS to show detailed errors:

<system.webServer>
    <httpErrors errorMode="Detailed" />
</system.webServer>

Alternatively, you can set this through IIS Manager:

  1. Open IIS Manager
  2. Select your site
  3. Double-click "Error Pages"
  4. Click "Edit Feature Settings"
  5. Select "Detailed errors"

In your Web.config, ensure custom errors are set to Off:

<system.web>
    <customErrors mode="Off" />
</system.web>

By default, IIS shows detailed errors only for local requests. To enable detailed errors for remote clients:

<system.webServer>
    <httpErrors errorMode="Detailed" existingResponse="PassThrough" />
</system.webServer>

For complex issues, IIS's Failed Request Tracing can provide detailed logs:

  1. In IIS Manager, select your site
  2. Double-click "Failed Request Tracing"
  3. Click "Enable" and specify a log directory
  4. Create a tracing rule for status code 500

Windows Event Viewer often contains more detailed error information:

  1. Open Event Viewer (eventvwr.msc)
  2. Navigate to Windows Logs > Application
  3. Look for errors from ASP.NET or IIS

For development environments, add this to Web.config to get rich error pages:

<system.web>
    <compilation debug="true" targetFramework="4.7.2" />
</system.web>
  • Missing dependencies or DLLs
  • Incorrect file permissions
  • Database connection issues
  • Configuration errors in Web.config
  • Application pool misconfiguration

You can create custom error handling middleware in Startup.cs:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/error");
    }
    
    // Other middleware
}

Nothing's more frustrating than seeing a plain "500 Internal Server Error" when deploying your ASP.NET Web API to IIS. The error message gives zero clues about what actually went wrong. As someone who's battled this issue multiple times, I'll share practical ways to extract detailed error information.

First, let's configure IIS to show more descriptive errors:


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

Windows Event Viewer often contains gold mines of information:

  1. Open Event Viewer (eventvwr.msc)
  2. Navigate to: Windows Logs → Application
  3. Look for red error entries around your API request time

This powerful IIS feature logs request processing details:


# PowerShell to enable tracing
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webServer/tracing/traceFailedRequests" -name "." -value @{path='*';verbosity='Verbose';statusCodes='500'}

Some frequent culprits I've encountered:

  • Missing dependencies: Ensure all NuGet packages are deployed
  • Configuration errors: Verify connection strings in web.config
  • Permission issues: Application pool identity needs proper access

When you need to dig deeper, attach Visual Studio to the IIS process:


1. In VS: Debug → Attach to Process
2. Select w3wp.exe (show processes from all users)
3. Reproduce the 500 error to hit breakpoints

Implement proper logging from the start. Here's a basic Serilog setup:


public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseSerilog((hostingContext, loggerConfiguration) => 
            loggerConfiguration.ReadFrom.Configuration(hostingContext.Configuration))
        .UseStartup<Startup>();