Search code examples
asp.netdockeriiscontainersinternal-server-error

Find the exact Internal Server Error in containerised ASP.Net application


500 Internal Server Error

I have an ASP.Net that runs locally in Visual Studio without error. But although successfully containerized, accessing the app saw 500 Internal Server Error. Wanted to find out what is the exact issue but couldn't find it.

Configured the web.config error mode to allow showing detailed errors, but still doesn't show detailed errors, so the issue might hit before the error handling module.

IIS error log

Getting information from the IIS log, the error sub status is 19, and the sc-win32-status is 13. It looks like the data invalid but doesn't tell what is the invalid data.

I guess it might be something to do with the web.config but not show how to pinpoint it:

<?xml version="1.0"?>

<configuration>
  <system.web>
    <customErrors mode="Off" />
    <httpCookies httpOnlyCookies="true" requireSSL="false"/>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.8">
      <assemblies>
        
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        
      </assemblies>
    </compilation>
    <pages controlRenderingCompatibilityVersion="4.0">
      <controls>
        <add tagPrefix="asp" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit"/>
      </controls>
    </pages>
    <globalization culture="en-US" uiCulture="en-US"/>
  </system.web>

  <system.webServer>
    <httpErrors errorMode="Detailed" />
    <defaultDocument>
      <files>
        <add value="terms.aspx"/>
      </files>
    </defaultDocument>
    <rewrite>
    </rewrite>
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0"/>
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.IdentityModel.Protocols.OpenIdConnect" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-6.6.0.0" newVersion="6.6.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.IdentityModel.Tokens" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-6.6.0.0" newVersion="6.6.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.IdentityModel.Tokens.Jwt" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-6.6.0.0" newVersion="6.6.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.IdentityModel.Protocols" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-6.6.0.0" newVersion="6.6.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>


Solution

  • The typical troubleshooting steps are,

    1. Identify the substatus code from IIS log files. As you showed in the question body, IIS log entry said 500.19.
    2. 500.19 indicates invalid IIS configuration (applicationHost.config and web.config), so have to review your configuration and see what's wrong.
    3. The presence of <rewrite></rewrite> requires URL Rewrite module to be installed, which isn't met in the default Docker base images.

    That explains why you saw the 500 error and concludes the investigation.

    You didn't see this error in VS, because IIS Express there has this module by default.

    While many other developers in the situation will need to use the MSI package to install URL Rewrite module in their containers, you simply need to delete the unused tag.

    Reference on such 500.19 errors

    https://docs.jexusmanager.com/tutorials/oob-500.html