G
Gorge
I have a http module that works fine. What it does, any incoming request it
checks against a ip database and filters it by country. It rejects
connectections if they are not from my country. This is all good, but it
only seems to work for the .Aspx pages. I need it to work for images. So,
under the configuration of the site, I added the extenstion .jpg and .jpeg
to point to c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll.
Now when viewing the image I get a link... so the code isn't work at all
for images if I point it to this dll. Is this the correct way I should be
doing it?
I'm quite lost. I thought the httpmodule would intercept any request to the
website.
Thanks
Code
a.. public class CountryFilter : IHttpModule
a.. {
a.. public void Dispose()
a.. {
a.. }
a..
a.. public void Init(HttpApplication context)
a.. {
a.. context.BeginRequest += new EventHandler(context_BeginRequest);
a.. }
a..
a.. private void context_BeginRequest(object sender, EventArgs e)
a.. {
a..
a.. HttpApplication app = (HttpApplication)sender;
a.. HttpContext context = ((HttpApplication)sender).Context;
a..
a.. // start checking country code
a.. GeoIPCountry cl = new GeoIPCountry(@"c:\\GeoIP.dat");
a..
a.. if
(cl.GetCountryCode(IPAddress.Parse(app.Context.Request.ServerVariables["REMOTE_ADDR"]))
!= "NZ")
a.. {
a.. context.Response.StatusCode = 403;
a.. context.Response.End();
a.. }
a.. }
a.. }
checks against a ip database and filters it by country. It rejects
connectections if they are not from my country. This is all good, but it
only seems to work for the .Aspx pages. I need it to work for images. So,
under the configuration of the site, I added the extenstion .jpg and .jpeg
to point to c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll.
Now when viewing the image I get a link... so the code isn't work at all
for images if I point it to this dll. Is this the correct way I should be
doing it?
I'm quite lost. I thought the httpmodule would intercept any request to the
website.
Thanks
Code
a.. public class CountryFilter : IHttpModule
a.. {
a.. public void Dispose()
a.. {
a.. }
a..
a.. public void Init(HttpApplication context)
a.. {
a.. context.BeginRequest += new EventHandler(context_BeginRequest);
a.. }
a..
a.. private void context_BeginRequest(object sender, EventArgs e)
a.. {
a..
a.. HttpApplication app = (HttpApplication)sender;
a.. HttpContext context = ((HttpApplication)sender).Context;
a..
a.. // start checking country code
a.. GeoIPCountry cl = new GeoIPCountry(@"c:\\GeoIP.dat");
a..
a.. if
(cl.GetCountryCode(IPAddress.Parse(app.Context.Request.ServerVariables["REMOTE_ADDR"]))
!= "NZ")
a.. {
a.. context.Response.StatusCode = 403;
a.. context.Response.End();
a.. }
a.. }
a.. }