IIS: Handler "aspNetCore" has a bad module "AspNetCoreModuleV2" in its module list

C#asp.net MvcIis.Net Core

C# Problem Overview


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

C# Solutions


Solution 1 - C#

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.

Solution 2 - C#

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

Or

Publish your project as self-contained.

Solution 3 - C#

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>

Solution 4 - C#

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.

Solution 5 - C#

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.

Solution 6 - C#

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/

Solution 7 - C#

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

Solution 8 - C#

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.

Solution 9 - C#

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.

Solution 10 - C#

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>

Solution 11 - C#

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>

Solution 12 - C#

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.

Solution 13 - C#

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

Solution 14 - C#

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.

Solution 15 - C#

None of the solutions worked for me. I had a 3.1 Asp.Net Core Web Api project I tried running with IISExpress. I tried:

  • installing latest 3.1 bundle
  • repairing latest 3.1 bundle
  • restarting PC
  • changing AspNetCoreModuleV2 to AspNetCoreModule inside web.config

The only thing that worked was completely commenting the handler.add entry, as following. Obviously this is a development only hack, but I just needed the damn thing to run in visual studio so I could debug it with Postman requests, and after wasting an hour on this BS (thanks Microsoft), this is the only thing that did the trick.

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionArun kumarView Question on Stackoverflow
Solution 1 - C#Shadi NamroutiView Answer on Stackoverflow
Solution 2 - C#RavinderReddy SeelamView Answer on Stackoverflow
Solution 3 - C#Zack EvansView Answer on Stackoverflow
Solution 4 - C#BinaryPatrickView Answer on Stackoverflow
Solution 5 - C#alansView Answer on Stackoverflow
Solution 6 - C#Anatolii HumennyiView Answer on Stackoverflow
Solution 7 - C#Promise PrestonView Answer on Stackoverflow
Solution 8 - C#N1njaB0bView Answer on Stackoverflow
Solution 9 - C#SomView Answer on Stackoverflow
Solution 10 - C#Alperen ARICIView Answer on Stackoverflow
Solution 11 - C#Hamed HosseiniView Answer on Stackoverflow
Solution 12 - C#JasmineUniqueView Answer on Stackoverflow
Solution 13 - C#MindRoasterMirView Answer on Stackoverflow
Solution 14 - C#manochehr shayestehView Answer on Stackoverflow
Solution 15 - C#Eternal21View Answer on Stackoverflow