Search code examples
asp.netiisweb-configblazor

Blazor Hosted (ASP.NET) HTTP Error 500.19 - Internal Server Error


From what I understand this error occurs when the web.config is not configured properly. However when I publish the app the following web.config gets generated

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath=".\Lotus.Server.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>
<!--ProjectGuid: 85a43eb6-3576-401d-b025-a15a2cc377b6-->

I first thought of installing URL Rewrite, this did not solve the problem. I am stressing out have tried almost everything any ideas on how to resolve it?

The error page looks like this:

enter image description here


Solution

  • I had this same problem and I was trying to fix it for 4 days. Then I found the solution.

    Firstly you need to download dotnet hosting

    https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/hosting-bundle?view=aspnetcore-7.0#direct-download-current-version

    Then after instalation try to restart IIS with cmd (run as admin and then write iisreset). If error page has changed we are going in good direction :)

    Now it should say that you are using wrong module (which indeed is true).

    Open IIS, get to your website and check installed modules. On list you should be able to see AspNetCoreModule but not AspNetCoreModuleV2.

    go to: %ProgramFiles%\IIS\Asp.Net Core Module\V2
    and copy aspnetcorev2.dll

    Then go into %SystemRoot%\system32\inetsrv\ and paste it

    Now after this, open config folder in %SystemRoot%\system32\inetsrv\ and then open applicationHost.

    IMPORTANT At this stage you need to turn off your iis

    Now find this line:

    <add name="AspNetCoreModule" image="%SystemRoot%\system32\inetsrv\aspnetcore.dll" />
    

    and add under it:

    <add name="AspNetCoreModuleV2" image="%SystemRoot%\system32\inetsrv\aspnetcorev2.dll" />
    

    And this same goes with this one:

    <add name="AspNetCoreModule" />
    

    add under it:

    <add name="AspNetCoreModuleV2" />
    

    Now save it, overwrite old one, and enable IIS. Go to your website, check modules and at the list you should be able to see AspNetCoreModuleV2:

    [AspNetCoreModule and AspNetCoreModuleV2 on list][1] [1]: https://i.sstatic.net/jC0JC.png