114

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

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
Arun kumar
  • 1,535
  • 3
  • 12
  • 17
  • 2
    Please refer this URL : https://stackoverflow.com/questions/53730020/deploying-a-plain-asp-net-core-2-2-web-app-in-azure-using-web-deploy-is-throwing/53730715#53730715 – Laxman Gite Dec 19 '18 at 07:49
  • Related post - [Why do we need web.config in ASP .NET 5 wwwroot?](https://stackoverflow.com/q/34482420/465053) – RBT Jan 28 '22 at 04:41

20 Answers20

121

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.

Shadi Alnamrouti
  • 11,796
  • 4
  • 56
  • 54
  • 2
    Installing the hosting bundle did not work. I use the workaround and then when publishing I have to add the "V2" to AspNetCoreModule. I am using IIS Express that comes with VS 2017. – JustJohn May 17 '19 at 21:27
  • Same: After installing the hosting bundle we still had to use the workaround. Why is the workaround "not recommended"? What problem does it cause? – R.D. Alkire Oct 02 '20 at 16:52
  • You need to install the hosting bundle that is compatible with your project .net version. https://dotnet.microsoft.com/download/dotnet-core/3.1 – Shadi Alnamrouti Oct 03 '20 at 17:23
  • 2
    For me, I had installed dotnet-hosting-5.0.0-win.exe from here https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/ and could not launch a default mvc site in IIS10 on Windwos 10. But I installed the hosting bundle in this answer's link (apparently dotnet-hosting-2.2.1-win.exe) and the site runs, tickety-boo. – bgmCoder Nov 19 '20 at 20:29
  • 1
    Now, I was wondering why 2.2 would work but not 5.0. In IIS's Modules, I see that `AspNetCoreModule`'s path leads to `%systemroot\system32\...%` whereas `AspNetCoreModule`'s path leads to `%ProgramFiles%\...` whose folder might not be on the `PATH` - in fact, that module is the only one that doesn't have a `PATH` going to `system32`. That V2 module is the 5.0. – bgmCoder Nov 19 '20 at 20:57
  • 1
    The installer for 5.0 installs the `AspNetCoreModuleV2` and that installer does not give you an install options to place it in `system32` like the other modules. – bgmCoder Nov 19 '20 at 21:00
  • 1
    I'm glad that he said that `Change AspNetCoreModuleV2 to AspNetCoreModule inside web.config` is not recommended and is just a workaround. Doing this is a bad choice, what you should do is figure out the actual problem and not just throw a bandaid on it. I'm not even sure where this workaround came from. It's nowhere in any Microsoft documentation. Someone must have just been fiddling around and got lucky. DO NOT DO THIS!! – Kelly Elton Dec 18 '21 at 17:33
  • 1
    See here for the [latest .NET version](https://dotnet.microsoft.com/en-us/download/dotnet) links, then choose "Hosting Bundle" from the available downloads. – Peet Brits Mar 22 '22 at 10:26
  • Installing the 2.2.1 bundle worked for me! A million thanks for that!! I was really stumped, having already installed a newer one after following the steps in a Microsoft doc. I'm trying to host a (self-hosted) Go-Gin web server out of IIS on Windows Server 2019 and damned if it didn't start working after 2.2.1 bundle. In case anyone's trying to do the same, this Medium article has the steps: https://medium.com/@mossila/running-go-behind-iis-ce1a610116df – kenswdev Aug 26 '22 at 20:18
  • You can find the latest hosting bundle [in the docs](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/hosting-bundle?view=aspnetcore-7.0#direct-download-current-version) or [as a direct download](https://dotnet.microsoft.com/permalink/dotnetcore-current-windows-runtime-bundle-installer) – Liam Bohl Jun 22 '23 at 22:04
43

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

Or

Publish your project as self-contained.

  • 12
    Installing the SDK isn't sufficient. You must select the 'hosting bundle' version of the runtime. Even without an IISReset this worked for me. – Simon_Weaver Dec 21 '18 at 01:28
  • 4
    I've installed 2.2 hosting bundle and still have this problem – BinaryPatrick Feb 01 '19 at 21:10
  • @BinaryPatrick Did you ever solve your issue? I have the same error even after installing the hosting bundle as well. – Tristan Jun 03 '19 at 18:56
  • Yes, I just posted my solution – BinaryPatrick Jun 05 '19 at 19:48
  • "self-contained" always works like a charm. Also we don't have to worry about framework version conflicts with other projects. Though the size of the project becomes larger. [Consider advantages and disadvantages.](https://learn.microsoft.com/en-us/dotnet/core/deploying/) – Mohsin Jun 20 '19 at 13:07
  • 6
    self contained publish still needs AspNetCoreModuleV2 to be installed – Sushil Mate Aug 29 '19 at 04:28
  • 'dotnet publish -r win-x64 --self-contained true' run this in the command prompt where the solution file is to publish the project as self contained, this is for 64 bit system. Enjoy :D – Grijan Feb 19 '21 at 05:24
  • Publish your project as self-contained worked for me. – M. Fawad Surosh Jul 07 '22 at 04:34
30

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>
Zack Evans
  • 309
  • 2
  • 2
14

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/

Dharman
  • 30,962
  • 25
  • 85
  • 135
Anatolii Humennyi
  • 1,807
  • 3
  • 26
  • 37
  • Oh its really confusing, thanks for that note, anything else we need to do once after installing the bundle can we directly publish our app? do we need to modify our .config in hosting space? – Nithin Paul Jan 03 '21 at 08:33
  • Wow! Thanks for posting! This fixed my issue. As Jack Reacher says, "Details matter". – PatrickSteele Jun 05 '23 at 22:44
12

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.

BinaryPatrick
  • 512
  • 6
  • 16
7

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.

alans
  • 1,022
  • 9
  • 17
  • 1
    This worked for me but, I have a cluster of machines with IIS behind a load balancer, and when I restored the shared config, it overwrote my changes. Either make sure you're verifying this in your shared `applicationhost.config`, or export your config again after installing the runtime. – BinaryPatrick Jul 01 '19 at 16:16
7

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

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
5

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.

Som
  • 51
  • 1
  • 2
  • I resolve with this. The order installation of the hosting bundle is very important. if you installed first the 3.1 you can not install the 2.1, then the solution is uninstall the 3.1, restart, install the 2.1 and then the 3.1 – freedeveloper Jul 23 '20 at 21:49
4

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.
N1njaB0b
  • 688
  • 6
  • 11
  • I got solution from this answer, I had entry for V2. I just changed my web.config to use V2 and it worked. – Amrendra Sep 30 '20 at 10:06
3

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>
dome
  • 820
  • 7
  • 20
Alperen ARICI
  • 204
  • 6
  • 13
2

According to this .NET Core issue:

asp.net core 2.x registers a handler named AspNetCoreModule, asp.net core 3.0 registers AspNetCoreModuleV2.

So, this error means that your app is looking for ASP.NET Core 2.x (or ASP.NET Core 1.x), which are out of support but can still be downloaded here (under "Out of Support versions"). So the ideal fix would be to move to ASP.NET Core 3.x, and others have expressed more nuanced and detailed thoughts, but for me simply installing the ASP.NET Core 2.2 Hosting Package fixed this problem immediately.

DonPedro
  • 76
  • 1
  • 4
1

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>
Hamed Hosseini
  • 182
  • 2
  • 13
1

Solution for netcoreapp5.0:

install console runtime and server hosting bundle from here: https://dotnet.microsoft.com/en-us/download/dotnet/6.0/runtime

In Webconfig modules have to be AspNetCoreModuleV2

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

Refresh and then restart website.

MKK
  • 2,431
  • 20
  • 16
0

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.

JasmineUnique
  • 61
  • 1
  • 1
  • 10
0

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://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.0#create-the-iis-site

MindRoasterMir
  • 324
  • 1
  • 2
  • 18
0

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.

0

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>
Eternal21
  • 4,190
  • 2
  • 48
  • 63
0

Publishing my project as self-contained worked for me.

M. Fawad Surosh
  • 450
  • 7
  • 20
0

In my case, no AspNetCoreModule was registered in IIS Modules. But the actual DLL was located in %SystemRoot%\system32\inetsrv\aspnetcore.dll

So I added this reference manually and it solved the problem:

add AspNetCoreModule manually to IIS modules (referencing aspnetcore.dll)

Serhii
  • 430
  • 3
  • 18
0

Uninstalling .Net run time (using the Hosting bundle link) and then installing then installing it back worked for me.

Sandhya M
  • 1
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 26 '23 at 15:35