2
votes

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
1
Yes. This isn't where the problem lies. You're looking in the wrong place. Dunno where its happening, tho.user1228
I agree with that but it's a default IIS 5.0 installation so I am not sure what is causing the problem. Has anyone tried to configure HttpModules for .htm files before?CueBall

1 Answers

1
votes

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:

context.Response.Write("/n/r");

//or

context.Response.Redirect("test.htm");

Everything then renders as you would expect