80
votes

I used angular .net core 2.2 template to build an application. In localhost working fine, When I host to IIS I'm getting this error. I'm using IIS 10 to host the application.

Error,

HTTP Error 500.21 - Internal Server Error Handler "aspNetCore" has a bad module "AspNetCoreModuleV2" in its module list

14

14 Answers

74
votes

Windows IIS

Solution: Install the hosting bundle.

Reason: Although the SDK normally contains the runtime, however, it seems the SDK installer is not registering the runtime correctly on the server.

Workaround (not recommended):

Change AspNetCoreModuleV2 to AspNetCoreModule inside web.config.

Azure platform hosting

Install the .NET Core runtime extension by selecting Extensions and then installing .NET Core Runtime.

37
votes

Install .Net Core 2.2 run-time bundle on hosting machine.

Or

Publish your project as self-contained.

27
votes

By removing V2 from modules="AspNetCoreModuleV2" worked for me. Note that my issue was related to running a .net core web api from visual studio. IE Express failed with a code 500 and upon investigating the error log describing "Handler 'aspNetCore' has a bad module.." was resolved by replacing with the below.

<handlers>
  <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
11
votes

UPDATE

This is a workaround that keeps your app on pre-v2 hosting. Please see alans answer and my comment for a more complete solution

ORIGINAL

I got this to work by adding the following code block to the .csproj for the web application.

<PropertyGroup>
  <TargetFramework>netcoreapp2.2</TargetFramework>
  <LangVersion>latest</LangVersion>
  <AspNetCoreModuleName>AspNetCoreModule</AspNetCoreModuleName>
  <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>

Obviously you'll want to update the netcoreapp version as you move on. This is how I was able to get things working. I'm not sure why simply installing the hosting bundle for 2.2 wasn't enough.

7
votes

There are a couple ways you can fix this:

  1. Install the latest .NET Core Runtime
  2. Inspect the applicationhost.config file used by your IIS. You should have the following entry in its appropriate locations:
<configuration>
    <system.webServer>
        ...
        <globalModules>
            ...
            <add name="AspNetCoreModuleV2" image="%IIS_BIN%\Asp.Net Core Module\V2\aspnetcorev2.dll" />
        </globalModules>
    </system.webServer>
    ...
    <location path="" overrideMode="Allow">
        <system.webServer>
            <modules>
                ...
                <add name="AspNetCoreModuleV2" lockItem="true" />
            </modules>
        </system.webServer>
    </location>
</configuration>

Just make sure you actually have the file for aspnetcorev2.dll in your IIS bin directory.

4
votes

Here is what worked for me:

  1. Check your applicationhost.config file and ensure you have the following entry in your globalModules section.

<add name="AspNetCoreModuleV2" image="%ProgramFiles%\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll" />
  1. Open IIS Manager, go to Modules. If AspNetCoreModuleV2 is not listed, click "Configure Native Modules..." and select "AspNetCoreModuleV2" and click OK to enable it.
4
votes

I had .net core 2.1, webAPI using Visual Studio 2019 (Windows 10). Installed hosting bundle (3.1.3). I tried to deploy to a folder, using publish option. The files were generated. I followed quick steps to create website in IIS. However I started getting HTTP Error 500.21. finally opened web.config file from deployment folder and did the reverse - change AspNetCoreModule to AspNetCoreModuleV2. All good now. thanks for all suggestions.

3
votes

I had this problem just a second ago. I replaced my code part in web.config with this.

OLD PART:

<handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" 
        resourceType="Unspecified" />
</handlers>

NEW PART:

<handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" 
        resourceType="Unspecified" />
</handlers>
3
votes

I'm posting my answer to save other people time who stuck with the same issue which took about 1 hour. My issue was that I installed an incorrect hosting budle. If your application uses .Net Core 3.1, you have to download it not with the link "x64", but with the link "Hosting bundle" on the next page: https://dotnet.microsoft.com/download/dotnet-core/3.1

My issue was that I thought that x64 hosting bundle is located in the link "x64" but it isn't. "x64" link doesn't contain the hosting bundle and will not solve the issue. The hosting bundle should be downloaded using only the link "Hosting Bundle":

enter image description here

The following article was very helpful for me to understand this issue: https://dotnetcoretutorials.com/2019/12/23/hosting-an-asp-net-core-web-application-in-iis/

2
votes

I had this same concern when trying to access a newly deployed web application on a Windows server.

It was throwing the error below:

enter image description here

Here's how I solved it:

First, I installed the latest version of .Net Core SDK using this link: https://dotnet.microsoft.com/download/dotnet/3.1. As of this writing, the latest version is 3.1.14 using the Windows x64 installer (since my Windows server is x64), which includes:

• .NET Core SDK 3.1.408
• .NET Core Runtime 3.1.14
• ASP.NET Core Runtime 3.1.14
• .NET Core Windows Desktop Runtime 3.1.14

Next, I installed the .NET Core Hosting bundle using this link https://dotnet.microsoft.com/permalink/dotnetcore-current-windows-runtime-bundle-installer which is an installer for the:

• .NET Core Runtime
• ASP.NET Core Module

The bundle allows ASP.NET Core apps to run with IIS.

Here's a screenshot of the webpage where you can download the .Net Core SDK and the .NET Core Hosting bundle

Here's a screenshot of the webpage where you can download the .Net Core SDK and the .NET Core Hosting bundle

Here's a screenshot of the downloaded .Net Core SDK and the .NET Core Hosting bundle files with their actual file names in the Downloads directory of a Windows PC.

Here's a screenshot of the downloaded  .Net Core SDK and the .NET Core Hosting bundle files with their actual file names in the Downloads directory of a Windows PC

After the Hosting Bundle is installed, a manual IIS restart may be required. For example, the dotnet CLI tooling (command) might not exist on the PATH for running IIS worker processes.

To manually stop and start IIS, execute the following commands in an elevated command shell (Run as administrator):

net stop was /y
net start w3svc

This time when I tried accessing the web app, it worked just fine.

Resources:

The .NET Core Hosting Bundle

That's all.

I hope this helps

0
votes

I had this same issue and what worked for me was to repair the install of the hosting bundle (Control Panel -> Programs and Features; right click on the hosting bundle install and click on 'Uninstall', then select 'Repair' in one of the following window that pops up.

0
votes

the best solution for when hosting has this problem is to override this value inside project.csproj file for release version. notice when use legacy version of module in new version of visual studio debugger not work. so the best solution is this .

    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
    <AspNetCoreModuleName Condition="'$(Configuration)' == 'Release'">AspNetCoreModule</AspNetCoreModuleName>
0
votes

ASP.NET Core 2.2 or later: For a 64-bit (x64) self-contained deployment that uses the in-process hosting model, disable the app pool for 32-bit (x86) processes.

In the Actions sidebar of IIS Manager > Application Pools, select Set Application Pool Defaults or Advanced Settings. Locate Enable 32-Bit Applications and set the value to False.

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.0#create-the-iis-site

0
votes

I had this same concern when trying to access a newly deployed web application on a Windows 10.

It was throwing the error below:

HTTP Error 500.21 - Internal Server Error Handler "aspNetCore" has a bad module "AspNetCoreModuleV2" in its module list

Here's how I solved it:

I installed the .NET Core Hosting bundle using this link https://dotnet.microsoft.com/permalink/dotnetcore-current-windows-runtime-bundle-installer which is an installer for the:

• .NET Core Runtime • ASP.NET Core Module

The bundle allows ASP.NET Core apps to run with IIS.