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.
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.
Open IIS Manager, go to Modules. If AspNetCoreModuleV2 is not listed, click "Configure Native Modules..." and select "AspNetCoreModuleV2" and click OK to enable it.
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.
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 .
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.
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.
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":
I had this same concern when trying to access a newly deployed web application on a Windows server.
It was throwing the error below:
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:
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 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.
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.
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.