Custom C # HttpModule Infinite Redirect Loop

I am writing a custom C # HttpModule that will handle requests from all file types. As a simple proof of concept, I installed a module by adding a link to the httpModules section in the web config and added application extensions for the IIS demo website with a link to aspnet_isapi.dll so that it currently only intercepts the request for ". Htm"

But even if there is no meaningful code in the "OnBeginRequest" event (code below), it causes an endless redirection loop. I am using IIS 5 on XP. Does anyone have any idea?

So far I've only seen examples of HttpModule for use with ASPX files, but can you customize them 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 ();

source to share

1 answer

OK. The problem was with the HttpModule itself.

It seems that you need to use the HttpApplication context to get it displayed on the client.

For example, after executing all of your custom logic, you need to write to the context:

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

// or

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

Everything displayed as expected



All Articles