问题标签 [httpmodule]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
2145 浏览

asp.net - ASP.NET Post Application_Error 事件

我试图找到一个将在所有Application_Error事件处理程序之后立即触发的事件,以便我可以使用自定义 HttpModule 修改发送的响应(弄乱状态代码和“位置”标头并专门创建一个新正文)。

我已经尝试过挂钩Application_EndRequest(因为我已经读到这是唯一可以保证触发的处理程序)但是这在请求处理中为时已晚,无法修改响应标头,我得到HttpException

0 投票
2 回答
2664 浏览

redirect - 在中等信任中从 Global.asax 重定向

我试图在 Global.asax 的 Application_Error 处理程序中进行重定向。一点都不花哨。

这在完全信任下工作得很好,但我需要让它在中等信任下工作。我在这里工作的代码需要在共享托管环境中正常运行(不幸的是,我无法控制这个要求)。

但是,当我在我们的开发环境(XP Pro / IIS 5.1)中配置站点以进行测试时:

它失败并出现以下错误:

其他一些值得注意的事情:

  • 无论是从 Global.asax 还是从 HttpModule 都会发生这种情况。
  • Response.Redirect(somePath) 也会发生这种情况。

感谢您提供的任何见解。我已经在谷歌上搜索了我的 $$ 折扣,但并不高兴。

谢谢!

0 投票
2 回答
581 浏览

asp.net - 通过 HttpHandlers 和 HttpModules 陌生性在 asp.net 2.0 中测量网络性能

我们有一个依赖 HttpModule 和 HttpHandlers 的性能测量模块,其工作方式如下:

  1. 请求进入服务器以获取页面。
  2. HttpModule_Begin 在 cookie 中写入开始时间。
  3. HttpModule_End 在 cookie 中写入结束时间。
  4. 在客户端,页面加载完成后,通过 HttpHandler_ProcessRequest 处理的 AJAX 触发一个特殊请求
  5. 在 HttpHandler_ProcessRequest 中,从之前的 HttpModule_End(存储在 cookie 中)写入的结束时间中减去 DateTime.Now 并将其存储在数据库中。我忘了提一件事:所有数据都是通过 cookie 共享的,所以 HttpHandler 只是从 cookie 中提取数据而没有任何会话 id 等……所有参与者都在同一个时区。

此过程在大多数情况下都可以正常工作,但有些情况会报告网络时间超过一个小时!这表明在写入结束时间和触发 AJAX 请求之间经过了非常长的时间,或者从触发 AJAX 请求到它到达应用服务器的时间之间经过了很长的时间。我试图弄清楚是什么导致了这个问题。为什么操作不只是超时?

0 投票
2 回答
1564 浏览

asp.net - IIS - Different processing of default document in Integrated Pipeline mode?

I have an HTTP Module to handle authentication from Facebook, which works fine in classic pipeline mode.

In integrated pipeline mode, however, I'm seeing an additional request pass through for the default document, which is causing the module to fail. We look at the request (from Facebook) to retrieve and validate the user accessing our app. The initial request authenticates fine, but then I see a second request, which lacks the posted form variables, and thus causes authentication to fail.

In integrated pipeline mode, an http request for "/" yields 2 AuthenticateRequests in a row:

  1. A request where AppRelativeCurrentExecutionFilePath = "~/"
  2. A request where AppRelativeCurrentExecutionFilePath = "~/default.aspx"

That second request loses all of the form values, so it fails to authenticate. In classic mode, that second request is the only one that happens, and it preserves the form values.

Any ideas what's going on here?

UPDATE: Here is an image of the trace from module notifications in IIS. Note that my module, FBAuth, is seeing AUTHENTICATE_REQUEST multiple times (I'd expect 2 - one for authenticate and one for postauthenticate, but I get 4).

Events raised multiple times

I'm starting to believe this has something to do with module/filter configuration because I've found a (Vista) box running the same code that doesn't fire these events repeatedly - it behaves as expected. I'm working through trying to figure out what the difference could be...

Thanks! Tom

0 投票
3 回答
488 浏览

c# - httpmodule, asp.net application interaction

Is there any way to call functions in a httpmodule from an asp.net application, even if the httpmodule is in another process? Better yet, in a situation where the application pool is running as a web garden (>1 worker process) how can I communicate with all of the httpmodules that are running?

0 投票
1 回答
1377 浏览

c# - 多个 httpmodule 实例

我有一个使用 Web 应用程序的 asp.net 网站,它们都在同一个应用程序池中(有 1 个工作进程)。该网站在其 web.config 文件中加载了一个 httpmodule,奇怪的是,主网站和应用程序都将由 httpmodule 的单独实例提供服务。为什么是这样?由于它们处于同一进程中,因此它们似乎应该使用一个实例。

此外,如果我尝试在应用程序中使用静态变量,它们将指向与 asp.net 网站不同的对象。和以前一样的问题,因为它们在同一个进程中,它们不应该是同一个对象还是.net在进程内部强加某种边界?

0 投票
2 回答
152 浏览

asp.net - 您使用 ASP.Net 框架的哪个部分对 IIS 的每个入站请求执行任意代码?

我想为通过 IIS 中某个网站的每个请求运行一段离散的 .Net 代码。这是完全独立的代码——它不会影响它之前或之后的任何东西——它会从请求中记录一些信息,然后结束。

请注意,这不是我可以放入 Application_OnRequestBegin 或其他一些 ASP.Net 文件的内容,因为我需要为非 .Net 文件(PDF、图像等)执行此操作。它需要执行通常不会命中 .Net 框架的请求。

我正在寻找一个 HTTP 模块吗?我已经使用了很多 RTFM,但似乎有许多不同的方法可以操纵管道,我不太确定应该使用哪一种。

0 投票
1 回答
87 浏览

asp.net - 请求管道中是否存在请求和响应都可用和填充的事件?

我需要绑定到请求和响应都填充的请求管道中的事件。Request 很简单,但我需要 Response 对象的 StatusCode。在管道中的哪个点填充响应?

0 投票
2 回答
5825 浏览

asp.net - 在 IIS 中管理后台线程有哪些最佳实践?

我写了一个产生后台线程的 HttpModule。我正在使用线程,就像在进程中运行的计划任务一样,这真的很方便。

跟踪此线程的最佳做法是什么?我以前从来没有这样做过,我对它的某些方面有点困惑:

  1. 我怎么知道线程是否仍在运行?我看到它完成了它的工作,但是还有其他方法可以知道它是否还活着?我下载了 ProcMon,但 w3wp.exe 产生了大量线程,所以我不知道哪个是我的线程。我给它起了名字,但这并没有帮助。

  2. 如果线程死了,我如何“抓住”线程?是否有某种 Dispose 方法可以让它写入 EventLog 或者如果它失败了?“垂死宣言”之类的?

  3. 如何主动停止线程?如果我想让它停止运行这个后台进程,如何在不反弹 IIS 的情况下杀死它?

  4. 无论如何要重新启动它,独立于 HttpModule 吗?(我猜这个答案是否定的……)

编辑:只是为了澄清,目的是我的线程永远不会消失。它运行一个函数,然后进入睡眠状态几分钟,然后唤醒并再次运行该函数。这不像是完成一项任务然后结束。

0 投票
1 回答
2334 浏览

asp.net - 是否可以在管道的早期处理和结束请求?

我有一个将事件处理程序绑定到 EndRequest 的 HttpModule。

有没有办法在事件处理程序中处理请求?意思是,我不只是想运行代码并保持请求移动——我想阻止它死在轨道上,返回一个 200 状态代码,然后收工,而不是请求继续执行下一步管道。