IIS: 处理程序“ aspNetCore”在其模块列表中有一个坏模块“ AspNetCoreModuleV2”

我用了棱角。Net core 2.2模板来构建应用程序。在本地主机工作良好,当我主机 IIS 我得到这个错误。我正在使用 IIS10托管应用程序。

错误,

HTTP 错误500.21-内部服务器错误 处理程序“ aspNetCore”的模块列表中有一个坏模块“ AspNetCoreModuleV2”

133200 次浏览

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

Or

Publish your project as self-contained.

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>

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.

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.

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.

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>

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.

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 .

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

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.

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

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/

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

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.

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>

Publishing my project as self-contained worked for me.

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)

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.

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.