IIS集成请求处理管道——修改请求

发布于 2024-07-04 19:11:05 字数 356 浏览 6 评论 0原文

我想在 IIS 集成请求处理管道模式下运行的 IIS7 中使用 HttpModule 来实现类似 ISAPI 过滤器的功能。

目标是在 Web 服务器级别查看传入请求,并将一些自定义 HttpHeader 注入到请求中。 (例如:HTTP\_EAUTH\_ID)

后来在 ASPX 页面的页面生命周期中,我应该能够使用该变量作为

string eauthId = Request.ServerVariables["HTTP\_EAUTH\_ID"].ToString();

因此在 Web 服务器级别实现此模块,是否可能改变 ServerVariables 集合?

I want to implement an ISAPI filter like feature using HttpModule in IIS7 running under IIS Integrated Request Processing Pipeline mode.

The goal is to look at the incoming request at the Web Server level, and inject some custom HttpHeaders into the request. (for ex: HTTP\_EAUTH\_ID)

And later in the page lifecycle of an ASPX page, i should be able to use that variable as

string eauthId = Request.ServerVariables["HTTP\_EAUTH\_ID"].ToString();

So implementing this module at the Web Server level, is it possible to alter the ServerVariables collection ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

就是爱搞怪 2024-07-11 19:11:05

我相信服务器变量列表仅包含从浏览器发送到服务器的标头。

I believe the server variables list only contains the headers sent from the browser to the server.

溺深海 2024-07-11 19:11:05

您将无法修改 HttpRequest.HeadersHttpRequest.ServerVariables 集合。 但是,您可以将您的信息附加到以下任何位置:

HttpContext.Current.Items
HttpContext.Current.Response.Headers

不幸的是,Request.Params、Request.QueryString、Request.Cookies、Request.Form(以及您想要填充的几乎任何其他位置)它是只读的。

如果您打算将其安装到 IIS 7 中,我强烈建议您不要使用反射,因为(可能)每个请求都会调用此代码。通过网络服务器,它需要非常快,而反射并不能减少它(除非你的用户很少)

祝你好运!

You won't be able to modify either the HttpRequest.Headers or the HttpRequest.ServerVariables collection. You will however be able to tack on your information to any of:

HttpContext.Current.Items
HttpContext.Current.Response.Headers

Unfortunately, Request.Params, Request.QueryString, Request.Cookies, Request.Form (and almost any other place you'd think of stuffing it is read only.

I'd strongly advise against using reflection if this is a HttpModule you're planning on installing into IIS 7. Given that this code will be called for (potentially) every request that goes through the web server it'll need to be really fast and reflection just isn't going to cut it (unless you have very few users).

Good luck!

(り薆情海 2024-07-11 19:11:05

HttpRequest.ServerVariables 属性是一个只读属性唯一的收藏。 所以,你不能直接修改它。 我建议将您的自定义数据存储在 httpcontext (或全局应用程序对象或您的数据库)中从您的 httpmodule 中读取该共享值,然后在 aspx 页面中读取该共享值。

如果您仍然想修改服务器变量,这个线程中提到了一种黑客技术使用反射。

HttpRequest.ServerVariables Property is a read-only collection. So, you cannot directly modify that. I would suggest storing your custom data in httpcontext (or global application object or your database) from your httpmodule and then reading that shared value in the aspx page.

If you still want to modify server variables, there is a hack technique mentioned in this thread using Reflection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文