G
Gorge
Hi Guys,
Still have a problem with httpmodule.
What I am trying to do is intercept all requests to my web app (images, html
pages etc linked via asp net dll). This works fine on my test machine.
The problem I am trying to solve:
A request comes in for an image. I check the IP address of incoming request.
If IP is not from my country, kill connection. This part works fine.
However, if the IP is from my country, I want normally processing to
contune. This doesn't seem to work. When I view the image, the browser says
content image/jpeg and all I have is a link of the url I am trying to
request with a 0 byte size.
So, I think I have something slightly wrong here. i have debugged it locally
and it seems fine, what am I doing wrong?
Below is my httpmodule (for a better view http://www.pastebin.ca/1450291):
public class CountryFilter : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
private void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
HttpContext context = ((HttpApplication)sender).Context;
// start checking country code
GeoIPCountry cl = new GeoIPCountry(@"e:\GeoIP.dat");
context.Response.Write(IPAddress.Parse(app.Context.Request.ServerVariables["REMOTE_ADDR"]));
//cl.GetCountryCode(IPAddress.Parse(app.Context.Request.ServerVariables["REMOTE_ADDR"]))
!= "NZ"
if (false)
{
context.Response.End();
}
}
}
Still have a problem with httpmodule.
What I am trying to do is intercept all requests to my web app (images, html
pages etc linked via asp net dll). This works fine on my test machine.
The problem I am trying to solve:
A request comes in for an image. I check the IP address of incoming request.
If IP is not from my country, kill connection. This part works fine.
However, if the IP is from my country, I want normally processing to
contune. This doesn't seem to work. When I view the image, the browser says
content image/jpeg and all I have is a link of the url I am trying to
request with a 0 byte size.
So, I think I have something slightly wrong here. i have debugged it locally
and it seems fine, what am I doing wrong?
Below is my httpmodule (for a better view http://www.pastebin.ca/1450291):
public class CountryFilter : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
private void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
HttpContext context = ((HttpApplication)sender).Context;
// start checking country code
GeoIPCountry cl = new GeoIPCountry(@"e:\GeoIP.dat");
context.Response.Write(IPAddress.Parse(app.Context.Request.ServerVariables["REMOTE_ADDR"]));
//cl.GetCountryCode(IPAddress.Parse(app.Context.Request.ServerVariables["REMOTE_ADDR"]))
!= "NZ"
if (false)
{
context.Response.End();
}
}
}