Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

IHttpModule not getting called

Posted on 2009-07-09
6
Medium Priority
?
596 Views
Last Modified: 2013-11-30
Put simply, is there any reason why an IHttpModule would not get called for requests for script files?  My module is set to gzip compress all JSON responses, and also all script files.  It works perfectly locally, but when I deploy it to my shared hosting account, it **only works for the JSON responses**.

Is there some IIS setting that they might have to cause requests for these files to bypass my HttpModule somehow?

Thanks!
0
Comment
Question by:ARACK04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 

Author Comment

by:ARACK04
ID: 24813775
Also, here's the complete code for my module:
using System;
using System.IO;
using System.IO.Compression;
using System.Globalization;
using System.Web;
 
 
public class JsonCompressionModule : IHttpModule {
    public JsonCompressionModule() {
    }
 
    public void Dispose() {
    }
 
    public void Init(HttpApplication app) {
        app.PreRequestHandlerExecute += new EventHandler(Compress);
    }
 
    private void Compress(object sender, EventArgs e) {
        HttpApplication app = (HttpApplication)sender;
        HttpRequest request = app.Request;
        HttpResponse response = app.Response;
 
        if (request.ContentType.ToLower(CultureInfo.InvariantCulture).StartsWith("application/json") ||
            request.Url.ToString().Contains(".js")) {
 
            if (!((request.Browser.IsBrowser("IE")) && (request.Browser.MajorVersion <= 6))) {
                string acceptEncoding = request.Headers["Accept-Encoding"];
 
                if (!string.IsNullOrEmpty(acceptEncoding)) {
                    acceptEncoding = acceptEncoding.ToLower(CultureInfo.InvariantCulture);
 
                    if (acceptEncoding.Contains("gzip")) {
                        response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
                        response.AddHeader("Content-encoding", "gzip");
                    } else if (acceptEncoding.Contains("deflate")) {
                        response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
                        response.AddHeader("Content-encoding", "deflate");
                    }
                }
            }
        }
    }
}

Open in new window

0
 
LVL 13

Accepted Solution

by:
crazyman earned 2000 total points
ID: 24814294
Script files are static content, and wont be mapped in iis to the asp.net runtime, therefore the request will never hit asp.net let alone your HttpModule.

You may append .js.aspx and they will come through asp.net but you will need to work your handler into mapping that to the correct phyical file...
0
 
LVL 13

Expert Comment

by:crazyman
ID: 24814332
This window in IIS controls what file extensions map to what, you can add to these as you wish.
IIS.gif
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:ARACK04
ID: 24814412
Genius, thanks!

Why did it work in localhost though?  Are requests through localhost not capable of knowing what's static, and just send everything through the ASP.NET runtime?
0
 

Author Comment

by:ARACK04
ID: 24814522
Instead of .js.aspx, couldn't I just add .js to the extensions handled by .NET directly?  Also, if I did that, would it still work for requests with a querystring added on, like

foo.js?ver=1.6    

I would assume so since requests like that still work for .aspx files.

Thanks for putting up with this simple (probably stupid) question!
0
 
LVL 13

Expert Comment

by:crazyman
ID: 24815051
It works on localhost because the development server in visual studio routes all traffic through the runtime.

You could indeed map .js to asp.net and handle them there.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question