问题标签 [ihttpmodule]

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 投票
1 回答
334 浏览

wcf - 将 log4net 和 IHttpModule 与 WCF 服务一起使用

我有一个包含许多网页和一些 WCF 服务的网站。

我有一个日志记录 IHttpModule 订阅 PreRequestHandlerExecute 并设置许多 log4net MDC 变量,例如:

这个模块适用于我的 aspx 页面。

为了使模块能够与 WCF 一起使用,我在 web.config 中设置了 aspNetCompatibilityEnabled="true",并在服务上设置了 RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed。

但是当调用服务方法时,MDC 不再包含任何设置值。我已经确认它们是通过在 PreRequestHandlerExecute 中放置一个日志记录方法来设置的。

我认为 MDC 正在丢失这些值,因为在日志中我可以看到 PreRequestHandlerExecute 处理程序方法和服务方法调用在不同的线程上。

在 wcf PerSession 服务中使用 ThreadContext.Properties发布log4net建议使用 log4net.GlobalContext 但我认为如果两个用户同时访问应用程序,因为 GlobalContext 由所有线程共享,该解决方案会遇到问题。

有没有办法使这项工作?

0 投票
0 回答
116 浏览

asp.net - 如果提前中止请求,如何防止 ASP.NET 网站初始化错误?

我尝试使用URLRewrite模块来重定向、重写和中止对站点的请求。但网站显示错误。

我写下了IHttpModule类似的方法,并调用HttpApplication.Context.Response.End();了“HttpApplication.BeginRequest”。这导致直接跳转到EndRequest事件中。站点没有预料到这一点,并抛出 InvalidOperationExceptionEndRequest表明即使没有初始化也试图清理一些数据库代码。与 相同URLRewrite

我认为这是因为End()调用跳过了初始化。

如何防止向用户显示此错误?无法修改第 3 方站点的情况下吞下它。

我正在尝试其他HttpApplication事件并且不希望处理请求,即没有任何内容作为请求的一部分写入数据库。这里还没有结果,还有什么其他选择?

0 投票
1 回答
182 浏览

c# - 使用 IHttpModule 记录请求长度

我制作了一个记录 Web 请求的 IHttpModule。它记录 POST 请求就好了。但是对于 GET 请求,长度似乎总是为零。有没有办法获取 GET 请求的长度?

0 投票
1 回答
318 浏览

c++ - Native IIS7.5 Module not running

I've created a simple CHttpModule that adds a custom header to all requests:

I've copied it to C:\Windows\System32\inetsrv, registered the module, and added it to the list. However, I'm not seeing the additional header in any of my requests. I created a similar managed module, installed it to the GAC, registered it, and it works fine. But this native module seems to do nothing. Is there another step required to get native modules to handle requests?

Also, I'm not sure if it matters, but the requests are being made to an ASP.NET site. Do native handlers not run for ASP.NET?

0 投票
1 回答
506 浏览

asp.net - ASP.NET Webforms Module, context user is null

When a video request is handled by the HTTP Module (code below) such as /website/uploads/Video/M2U00001_2.mp4 the _context.User is null.

When I run this in VS2010 on my local machine using the Visual Studio Development server _context.User is set. After I deploy to IIS 7 (.net 4.0) _context.User is Null.

'_context.User' is not Null when the http module processes an aspx page but it is Null when processing javascript, images, videos or CSS.

Can anyone explain why _context.User is null and possible solutions that will ensure _context.User is not null.

0 投票
1 回答
176 浏览

webforms - 用户在 ASP.NET WebForms HTTP 模块中设置为空

我在 asp.net Web 应用程序中有以下自定义模块。该模块在我的 PC 上通过 chrome 工作,但是当我尝试从 Android 访问视频时,由于未设置用户 ID(_context.User)而出现错误。这一切都发生在我登录应用程序之后。因此 _context.User 应该被设置。

我会认为,因为在这个级别,您正在处理 HTTP 请求和响应,该模块适用于任何设备。

我有两个问题。

有没有办法使这项工作?

导致此问题的 Android 平板电脑和 PC 发送的请求有什么区别?

公共类 VideoSecurityModule 实现 IHttpModule 实现 IRequiresSessionState Private WithEvents _context 作为 HttpApplication

结束类

0 投票
1 回答
782 浏览

asp.net - 注册到同一个 EventHandler 时几个 httpModules 的执行顺序

我正在编写一个 httpModule,计划是将模块附加到PreRequestHandlerExecute事件,而我看到已经存在附加到同一事件的模块。

我的问题是注册到同一事件的 httpModules 的执行顺序是什么?

如果在这种情况下PreRequestHandlerExecute注册到同一个事件,有没有办法可以控制 httpModules 的执行顺序?

0 投票
2 回答
3345 浏览

performance - Sitecore HttpModules being initialized second time

We are experiencing CPU peaks on sudden moments. After checking our Sitecore logs, I have noticed that there are a lot of log entries with "11:49:26 INFO HttpModule is being initialized" . As far is know this should only be initialized on the startup of the application.. And this still appear after the application was started up. Am I right? If so, where could these modules been initiliazed for the second time?

0 投票
1 回答
2142 浏览

c# - 仅第一次调用 IIS AuthenticateRequest 上的 WCF 服务身份验证时

我有一个 OData WCF 服务的工作实现,现在需要使用基本的自定义身份验证在 IIS 中发布。

实现基于Microsoft OData 示例,并且在 IIS Express 下运行良好。当我将其发布到仅启用基本身份验证的 IIS 7.5 时,仅在初始请求时调用 AuthenticateRequest 处理程序,它返回状态代码 401 并要求进行身份验证。

后续请求不再调用 AuthenticateRequest。在IIS上调试服务时,肯定会调用BeginRequest,只是管道中不存在AuthenticateRequest?IIS Express 中的每个请求都会调用两者。

IIS 身份验证配置:

IIS 身份验证配置

IHttpModule 代码:

网络配置:

还有一个问题:为什么身份验证在 Visual Studio 2012 调试服务器中有效,但在 IIS 7.5 中无效?完整的测试项目可以从这里下载。

编辑:

我在 CreateNotAuthorizedResponse 函数和 response.End() 中注释掉了导致异常的过多测试代码(我在发布前的最后一分钟添加了它)。

在检查请求时,除了 Cookie 可能由于某种原因导致 IIS 跳过身份验证之外,一切似乎都应该正常工作。在前 2 个原始请求 - 回复对下方:

请求 1:

回复 1:(由 CreateNotAuthorizedResponse 方法创建)

请求 2(当输入 test:test - dGVzdDp0ZXN0):

响应 2(调用了 BeginRequest 但未调用 AuthenticateRequest):

0 投票
1 回答
1052 浏览

c# - HttpModule - 异步不起作用

我写了一个异步HttpModule记录所有进入网站的请求。当请求到达网站时,自定义 http 模块调用 WebAPI 将信息记录到数据库中。.Net 4.5/Visual Studio 与 IIS Express。

“api/activity”的简化 WebAPI 代码。

问题是:当PostAsJsonAsync被执行时,代码会停在那里。这是正确的,因为代码必须等待。但是调用例程没有像预期的那样异步继续,网站响应慢了 30 秒。

这段代码有什么问题?挂钩异步HttpModule不应该干扰 Http 应用程序的流程?目前,当我访问该网站时,代码被阻止了。