老实说,我试过对IIS耍卑鄙的花招,就在我以为我能逃脱的时候,我意识到我的解决办法不起作用。以下是我试图做的:

1)我有ASP。NET应用程序,它拥有继承IProcessHostPreloadClient的Preloader类,并在Preload方法实现中进行所有繁重的初始化(应用程序很复杂,它是一个巨大系统的一部分,所以它需要大约2分钟来建立到所有必要服务的连接并预实例化一些Unity注册)。

2)我有很多工作需要做的应用程序关闭(取消订阅,断开连接,处理,…),我猜最好的地方是在*Application_End*方法位于Global.asax。

3) Everything works just fine when I have user activity (first request after the Application Pool that contains aforementioned web application is started will cause *Application_Start* to be called and afterwards *Application_End* is called on Application Pool stop or recycle), but problems occur when there is no user activity and application tries to restart itself after being active for 48 hours (configured requirement). Since there was no requests, application officially didn't get started. Ergo, it can't be gracefully stopped since *Application_End* won't be called.

4)现在轮到麻烦的部分了……我尝试在Preload方法的末尾从代码中发出GET请求,它工作了。但这个解决方案对我来说很糟糕,尽管它很有效。所以,我尝试了很多东西,我最后尝试的是:

SimpleWorkerRequest swr = new SimpleWorkerRequest(string.Empty, string.Empty, tw);
HttpRuntime.ProcessRequest(swr);

... 这已经达到了它的目的。*Application_Start*被调用,(我检查了响应,它包含登录页面,应该在初始请求中显示)和应用程序池关闭应用程序通过在*Application_End*中做必要的工作优雅地结束。

BUT

应用程序以这种方式启动(预加载和初始化)后,当我想通过Web浏览器访问应用程序时,会发生以下情况:

HTTP错误500.21 -内部服务器错误 “ExtensionlessUrlHandler-Integrated-4.0”在它的模块列表中有一个坏模块“ManagedPipelineHandler”

我想不通。有人能告诉我为什么会发生这种情况以及如何解决吗?

如果我不明白这一点,我将回到第一个解决方案(从代码发送GET请求),但这个问题会困扰我,因为我甚至不知道哪里出了问题。


当前回答

你可以通过将iis中的“ExtensionlessUrlHandler-Integrated-4.0”类型更改为System.Web.DefaultHttpHandler来修复

其他回答

对于Windows 10 / Windows Server 2016使用以下命令:

dism /online /enable-feature /featurename:IIS-ASPNET45 /all

使用aspnet_regiis的建议答案在Windows 10(创建者更新及更高版本)或Windows Server 2016上不起作用:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i Microsoft (R) ASP.NET RegIIS version 4.0.30319.0 Administration utility to install and uninstall ASP.NET on the local machine. Copyright (C) Microsoft Corporation. All rights reserved. Start installing ASP.NET (4.0.30319.0). This option is not supported on this version of the operating system. Administrators should instead install/uninstall ASP.NET 4.5 with IIS8 using the "Turn Windows Features On/Off" dialog, the Server Manager management tool, or the dism.exe command line tool. For more details please see http://go.microsoft.com/fwlink/?LinkID=216771. Finished installing ASP.NET (4.0.30319.0).

有趣的是,“打开/关闭Windows功能”对话框不允许我取消。net或ASP。NET 4.6,并且只有上面的DISM命令可以工作。不确定featurename是否正确,但它对我有用。

尝试重新注册ASP。使用aspnet_regiis -i。这对我很管用。

.NET 4可能的路径(从提升的命令提示符):

c:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i

http://forums.iis.net/p/1190643/2026401.aspx

在我的情况下(Windows 10 + IIS 10),我必须打开“打开或关闭Windows功能”,然后进入Internet信息服务>万维网服务>应用程序开发功能>,并检查ASP。NET 4.6

这个https://stackoverflow.com/a/13266763/1277458工作得很完美。但是如果你是64位操作系统,在path中使用Framework64而不是Framework:

c:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i

对我来说,从服务器上删除WebDAV会导致应用程序在使用PUT或DELETE时返回503服务不可用错误消息,所以我重新安装了它。我还尝试完全删除。net Framework 4.5并重新安装它,并尝试按照建议重新注册,但没有效果。

我能够通过禁用个人应用程序池的WebDAV来修复这个问题,这在使用PUT或DELETE时阻止了“坏模块”错误。

禁用单个应用程序池的WebDAV:

单击受影响的应用程序池 在列表中找到WebDAV创作工具 点击打开 单击右上角的“禁用WebDAV”。

我们daaaa !

我仍然在我的网中留下了删除项。配置文件。

 <system.webServer>
    <modules>
      <remove name="WebDAVModule"/>
    </modules>
    <handlers>
      <remove name="WebDAV" />
    </handlers>
 <system.webServer>

这个链接是我找到说明的地方,但不是很清楚。