ASP.NET Core无法在IIS下运行:HTTP错误500.0-ANCM进程内处理程序加载失败 [英] ASP.NET Core fails to run under IIS: HTTP Error 500.0 - ANCM In-Process Handler Load Failure

查看:5463
本文介绍了ASP.NET Core无法在IIS下运行:HTTP错误500.0-ANCM进程内处理程序加载失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将Web应用程序从ASP.NET(框架)MVC升级到ASP.NET Core 2.2。该应用程序在IIS Express下运行良好,但是,一旦我尝试在IIS Express下运行它,就会出现一般错误:


HTTP错误500.0 -ANCM进程内处理程序加载失败常见原因导致此问题的
:未找到指定版本的Microsoft.NetCore.App或
Microsoft.AspNetCore.App。
应用程序未引用处理中的请求
处理程序Microsoft.AspNetCore.Server.IIS。 ANCM找不到dotnet。


我在网上搜索,发现许多开发人员都遇到了同样的问题,微软确实错过了这一点,使在IIS下开发ASP.NET Core应用程序变得尽可能痛苦。无论如何,我想突破过去24个小时一直在撞墙的那堵砖墙,所以可以使用一些帮助。



到目前为止已经尝试过:




  • 安装了最新版本的.NET Core Runtime and Hosting Bundle,版本2.2.4。 / p>


  • 安装了最新版本的.NET Core SDK,版本为2.2.203。


  • 确保 dotnet可从命令行运行,并且在我的环境变量中x64版本早于x86版本。





C:\WINDOWS\system32>其中dotnet C:\Program Files\dotnet\dotnet.exe
C:\Program Files(x86)\ dotnet\dotnet.exe





  • 试图从aspNetCore更改自动生成的Web.config aspNetCore的processPath =%LAUNCHER_PATH% arguments =%LAUNCHER_ARGS%,但是每次我b更改都不会保留,更改不会保留在我的Web应用程序中,Web.config恢复为原始%LAUNCHER_PATH%值。


  • 试图在Web中将 AspNetCoreModuleV2更改为 AspNetCoreModule。配置。


  • 已将IsTransformWebConfigDisabled = true添加到Web.csproj文件中,以防止覆盖自定义Web.config。它没有用,Web.config仍然被覆盖。


  • 尝试将Web.csproj中的AspNetCoreHostingModel = InProcess切换为RuntimeFrameworkName = Microsoft.AspNetCore.App


  • 清理解决方案,以及手动删除bin,obj甚至.vs文件夹。




这些方法都无济于事,我仍然遇到相同的ANCM进程内处理程序加载失败错误。事件查看器确实显示了一个更有用的错误:


应用程序'C:\Housters\Web\'无法执行开始。在'C:\Housters'Web\%LAUNCHER_PATH%.exe'中找不到可执行文件


,对此我无能为力,因为我的Web.config更改不会持续存在。但是,实际上,默认设置应该可以立即使用,我们不必为了使IIS开发正常工作而一jump而就。当ASP.NET Core项目默认情况下仅生成.dll时,为什么要查找.exe?为什么不将%LAUNCHER_PATH%替换为正确的路径,例如 bin / Debug?



编辑:我还应该提到,有时我可以使自定义Web.config持久化,而当我这样做时每次尝试运行Web应用程序时,我都会收到一个JIT调试器提示:





选择调试或查看事件日志只会给我一个非常不友好的错误消息:


正在对应用程序进行故障修复名称:w3wp.exe,版本:10.0.17134.1,时间
时间戳:0xed729d4e故障模块名称:KERNELBASE.dll,版本:
10.0.17134.556,时间戳:0xb9f4a0f1异常代码:0xc0020001故障偏移量:0x000000000003a388错误的进程ID:0x2650错误的
应用程序启动时间:0x01d502b1f21b112e错误的应用程序路径:
c:\windows\system32\inetsrv\w3wp.exe错误模块路径:
C:\ WINDOWS\System3 2\KERNELBASE.dll报告ID:
5b5c14cb-8ffa-47b4-8cc1-42f951bc1256错误的程序包全名:
错误的程序包相对应用程序ID:



解决方案

此错误是因为您未指定是要托管网站还是进行中...可以使用UseIIS()指定。



尝试将Program.cs中的CreateWebHostBuilder方法更改为:

 公共静态IWebHostBuilder CreateWebHostBuilder(string [] args)
{
var env = Environment.GetEnvironmentVariable( ASPNETCORE_ENVIRONMENT);
var builder = WebHost.CreateDefaultBuilder(args);

if(env == EnvironmentName.Staging || env == EnvironmentName.Production)
builder.UseIIS();

builder.UseStartup< Startup>();
退货建设者
}

我通过添加以下内容在.pubxml部署配置文件中设置ASPNETCORE_ENVIRONMENT:

 < PropertyGroup> 
< EnvironmentName> Staging< / EnvironmentName>
< / PropertyGroup>


I just upgraded my web application from ASP.NET (Framework) MVC to ASP.NET Core 2.2. The application runs fine under IIS Express, however as soon as I try to run it under IIS it gives the generic error:

HTTP Error 500.0 - ANCM In-Process Handler Load Failure Common causes of this issue: The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found. The in process request handler, Microsoft.AspNetCore.Server.IIS, was not referenced in the application. ANCM could not find dotnet.

I've searched the web and see that many developers are running into the same issue, it seems that Microsoft really missed the mark on this one and have made it as painful as possible to develop ASP.NET Core apps under IIS. Regardless, I'd like to break through this brick wall that I've been hitting my head against for the last 24 hours, so could use some help.

Things I've tried so far:

  • Installed the latest version of .NET Core Runtime and Hosting Bundle, version 2.2.4.

  • Installed the latest version of .NET Core SDK, version 2.2.203.

  • Ensured that "dotnet" is runnable from command line, and that the x64 version is before the x86 version in my environment variables.

C:\WINDOWS\system32>where dotnet C:\Program Files\dotnet\dotnet.exe C:\Program Files (x86)\dotnet\dotnet.exe

  • Tried changing my auto-generated Web.config from aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" to aspNetCore processPath="dotnet" arguments="./Housters.Web.dll" however the changes don't stick, every time I build my web application the Web.config gets reverted back tot he original %LAUNCHER_PATH% values.

  • Tried changing "AspNetCoreModuleV2" to "AspNetCoreModule" in the Web.config.

  • Added IsTransformWebConfigDisabled=true to my Web.csproj file in order to keep my custom Web.config from being overwritten. It didn't work, the Web.config is still overwritten.

  • Tried switching AspNetCoreHostingModel=InProcess to RuntimeFrameworkName=Microsoft.AspNetCore.App in my Web.csproj file.

  • Cleaning the solution, as well as manually deleting the bin, obj, and even .vs folders.

None of these methods helped, I still get the same ANCM In-Process Handler Load Failure error. The Event Viewer does show a more useful error:

Application 'C:\Housters\Web\' wasn't able to start. Executable was not found at 'C:\Housters\Web\%LAUNCHER_PATH%.exe'

However, I can't do anything about that because my Web.config changes don't persist. But really, the default settings should work out of the box, we shouldn't have to jump through hoops to get IIS development working. Why is it looking for an .exe when an ASP.NET Core project by default only generates a .dll? And why isn't it replacing %LAUNCHER_PATH% with the correct path, e.g. "bin/Debug"?

EDIT: I should also mention that at times I've been able to get my custom Web.config to persist, and when I do then every time I try to run the web application I get a JIT debugger prompt:

Choosing to debug, or viewing the event log just gives me a really unfriendly error message:

Faulting application name: w3wp.exe, version: 10.0.17134.1, time stamp: 0xed729d4e Faulting module name: KERNELBASE.dll, version: 10.0.17134.556, time stamp: 0xb9f4a0f1 Exception code: 0xc0020001 Fault offset: 0x000000000003a388 Faulting process id: 0x2650 Faulting application start time: 0x01d502b1f21b112e Faulting application path: c:\windows\system32\inetsrv\w3wp.exe Faulting module path: C:\WINDOWS\System32\KERNELBASE.dll Report Id: 5b5c14cb-8ffa-47b4-8cc1-42f951bc1256 Faulting package full name: Faulting package-relative application ID:

解决方案

You're getting this error because you're not specifying if you want the website hosted in process or out of process... in process can be specified by using UseIIS().

Try changing your CreateWebHostBuilder method in Program.cs to:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) 
{
    var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
    var builder = WebHost.CreateDefaultBuilder(args);

    if (env == EnvironmentName.Staging || env == EnvironmentName.Production)
        builder.UseIIS();

    builder.UseStartup<Startup>();
    return builder;
}

I set ASPNETCORE_ENVIRONMENT in my .pubxml deployment profile by adding:

  <PropertyGroup>
    <EnvironmentName>Staging</EnvironmentName>
  </PropertyGroup>

这篇关于ASP.NET Core无法在IIS下运行:HTTP错误500.0-ANCM进程内处理程序加载失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆