本文介绍了处理程序“ExtensionlessUrlHandler-Integrated-4.0"有一个坏模块“ManagedPipelineHandler"在其模块列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

老实说,我曾试图在 IIS 上使用一个肮脏的把戏,就在我以为我会侥幸逃脱时,我意识到我的解决方法不起作用.这是我尝试做的:

1) 我有一个 ASP.NET 应用程序,它具有 Preloader 类,该类继承了 IProcessHostPreloadClient 并在 Preload 方法实现中完成所有繁重的初始化(应用程序很复杂,而且它是庞大系统的一部分,因此它需要大约 2 分钟的时间来建立与所有必要服务的连接并预先实例化一些 Unity 注册).

2) 我有很多工作需要在应用程序关闭时完成(取消订阅、断开连接、处理...),我想最好的地方是在位于 Global.asax.

3) 当我有用户活动时,一切正常(在包含上述 Web 应用程序的应用程序池启动后的第一个请求将导致 *Application_Start* 被调用,之后 *Application_End* 在应用程序池停止或回收时被调用),但是当没有用户活动并且应用程序在活动 48 小时(配置要求)后尝试重新启动时会出现问题.由于没有请求,申请正式没有开始.因此,它不能优雅地停止,因为 *Application_End* 不会被调用.

4) 现在是混乱的部分......我试图从 Preload 方法末尾的代码发出一个 GET 请求,并且它奏效了.但是这个解决方案对我来说似乎很糟糕,即使它有效.所以,我尝试了很多东西,而我尝试的最后一件事是:

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

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

但是

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

HTTP 错误 500.21 - 内部服务器错误处理程序ExtensionlessUrlHandler-Integrated-4.0"在其模块列表中有一个坏模块ManagedPipelineHandler"

我无法弄清楚这一点.谁能告诉我为什么会发生这种情况以及如何解决它?

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

解决方案

问题

您正在使用 SimpleWorkerRequest 在它不是为它设计的场景中.您正在在 IIS 内使用它.如果您查看之前的 MSDN 链接(重点是我的):

提供 HttpWorkerRequest 抽象类的简单实现,可用于在 Internet 信息服务 (IIS) 应用程序之外托管 ASP.NET 应用程序.您可以直接使用 SimpleWorkerRequest 或扩展它.

此外,如果您查看 System.Web.Hosting 命名空间(SimpleWorkerRequest 在这个命名空间中),你也会看到类似上面的内容(同样,重点是我的):>

System.Web.Hosting 命名空间提供了托管 ASP.NET 应用程序的功能,这些应用程序来自Microsoft Internet Information Services (IIS) 之外的托管应用程序.

解决方案

我建议删除对 SimpleWorkerRequest 的调用.相反,您可以使用 Microsoft 解决方案来确保您的网站在回收后自动启动.您需要的是 Microsoft IIS 7.5 的应用程序初始化模块.配置并不复杂,但您需要了解确切的选项.这就是为什么我还推荐 IIS 7.5 的应用程序初始化 UI.用户界面由 MSDN 博主编写.

那么微软的解决方案究竟是做什么的呢?它执行您正在尝试执行的操作 - IIS 在应用程序池启动后向您的网站发送获取"请求.

To be honest, I've tried to turn a dirty trick on IIS and just when I thought that I was going to get away with it, I realized my workaround doesn't work. Here's what I've tried to do:

1) I have ASP.NET application which has Preloader class that inherits IProcessHostPreloadClient and does all the heavy initialization in Preload method implementation (application is complex and it's a part of an enormous system, so it requires approximately 2 minutes to establish connections to all necessary services and pre-instantiate some Unity registrations).

2) I have a lot of work that needs to be done on application shutdown (unsubscribing, disconnecting, disposing,...), and I guess the best place to do it is in *Application_End* method located in 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) Now comes the messy part... I've tried to make a GET request from code at the end of the Preload method, and it worked. But this solution seemed bad to me, even though it worked. So, I've tried a lot of things, and the last thing I tried was this:

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

... and that has done it's purpose. *Application_Start* was called, (I've checked response, it was containing login page that was supposed to be displayed in initial request) and on Application Pool shutdown application ended gracefully by doing necessary work in *Application_End*.

BUT

After the application was started (preloaded and initiated) in this manner, this is what happened when I wanted to reach application via Web browser:

I am unable to figure this out. Can anybody tell me why this happens and how to fix it?

If I don't figure this out, I will go back to first solution (sending GET request from code) but this problem will bug me since I don't even have an idea what's wrong.

解决方案

The problem

You are using SimpleWorkerRequest in a scenario that it wasn't designed for. You are using it inside of IIS. If you look at the prior MSDN link (emphasis is mine):

Also, if you look at the MSDN documentation for the System.Web.Hosting namespace (SimpleWorkerRequest is in this namespace), you will also see something similar to the above (again, emphasis is mine):

The solution

I would recommend removing the call to SimpleWorkerRequest. Instead, you can use a Microsoft solution to make sure your web site automatically starts up after it recycles. What you need is the Microsoft Application Initialization Module for IIS 7.5. It is not complicated to configure, but you need to understand the exact options. This is why I would also recommend the Application Initialization UI for IIS 7.5. The UI is written by an MSDN blogger.

So what exactly does the Microsoft solution do? It does what you are trying to do - IIS sends a "get" request to your website after the application pool is started.

这篇关于处理程序“ExtensionlessUrlHandler-Integrated-4.0"有一个坏模块“ManagedPipelineHandler"在其模块列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 03:04