自定义 C# HttpModule 无限重定向循环
我正在编写一个自定义 c# HttpModule,它将处理来自所有文件类型的请求。作为一个简单的概念证明,我通过添加对 Web 配置的 httpModules 部分的引用来设置该模块,并通过对 aspnet_isapi.dll 的引用为演示 IIS 网站添加应用程序扩展,以便它当前仅拦截“. htm” 文件
但即使“OnBeginRequest”事件中没有重要代码(代码如下),它也会导致无限重定向循环。我在 XP 上使用 IIS 5 有人有什么想法吗?
到目前为止,我只看到了与 ASPX 文件一起使用的 HttpModule 示例,但您肯定可以为任何文件类型进行配置吗?
#region IHttpModule Members public void Dispose() { } public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(OnBeginRequest); } /// /// /// /// public void OnBeginRequest(Object s, EventArgs e) { HttpApplication context = s as HttpApplication; Uri currentURL = context.Request.Url; string pageName = currentURL.Segments.Last().ToLower(); } #endregion
I am writing a custom c# HttpModule that will handle requests from all file types. As a simple proof of concept I have setup the module by adding a reference to the httpModules section of the web config and added application extensions for the demo IIS website with a reference to the aspnet_isapi.dll so that it currently only intercepts request for ".htm" files
But even if there is no significant code in the "OnBeginRequest" event (code below) it causes an infinite redirect loop. I am using IIS 5 on XP Anyone got any ideas?
So far I have only seen HttpModule examples for use with ASPX files but surely you can configure the for any file type?
#region IHttpModule Members public void Dispose() { } public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(OnBeginRequest); } /// /// /// /// public void OnBeginRequest(Object s, EventArgs e) { HttpApplication context = s as HttpApplication; Uri currentURL = context.Request.Url; string pageName = currentURL.Segments.Last().ToLower(); } #endregion
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的。问题实际上出在 HttpModule 本身。
看来您必须使用 HttpApplication 上下文才能在客户端上呈现。
例如,在执行完所有自定义逻辑后,您需要写入上下文:
然后一切都会按照您的预期呈现
OK. The problem was actually in the HttpModule itself.
It appears that you have to use the HttpApplication context in order for it to render on the client.
For Example after you have performed all your custom logic you need to write to the context:
Everything then renders as you would expect