IIS集成请求处理管道——修改请求
我想在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信服务器变量列表仅包含从浏览器发送到服务器的标头。
I believe the server variables list only contains the headers sent from the browser to the server.
您将无法修改
HttpRequest.Headers
或HttpRequest.ServerVariables
集合。 但是,您可以将您的信息附加到以下任何位置:不幸的是,
Request.Params、Request.QueryString、Request.Cookies、Request.Form
(以及您想要填充的几乎任何其他位置)它是只读的。如果您打算将其安装到 IIS 7 中,我强烈建议您不要使用反射,因为(可能)每个请求都会调用此代码。通过网络服务器,它需要非常快,而反射并不能减少它(除非你的用户很少)
祝你好运!
You won't be able to modify either the
HttpRequest.Headers
or theHttpRequest.ServerVariables
collection. You will however be able to tack on your information to any of: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!
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.