views:

41

answers:

2

We have a web app where we need to redirect customers from .com to .co.uk domains based on the geolocation of ther IP address. When/where should I do this?

The content will change slightly based on their location, but I think I can handle that OK. However, if anyone has any comments on the best way to handle this, I'd like to hear those comments as well.

+1  A: 

I would use an HttpModule. It's the earliest place to do the redirection.

Bryan
Doesn't Global.asax provide the same events an HttpModule has access to?
Esteban Araya
Yes, but there are couple reasons to prefer HttpModule. Here is a good read: http://codebetter.com/blogs/karlseguin/archive/2006/06/12/146356.aspx
Bryan
+1  A: 

If you want to do this in application code, I would do this as early as the IP is available, in the Application_BeginRequest handler in global.asax:

protected void Application_BeginRequest(object sender, EventArgs e)
{
  var ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
  //Redirect here...
}
Nick Craver
Is there any reason why I'd prefer code over a config setting?
Esteban Araya
There's no a config setting for this built in...that I've ever seen anyway, your options are an HttpModule, Global.asax code (ease of use/flexibility, though it's equivalent to an HttpModule in those aspects) or something in the form of an IIS module.
Nick Craver
Global.asax is deprecated. There are several good reasons to use HttpModule instead, and it's just as easy.
Bryan
@Bryan - Can you please link me to where Global is deprecated?
Nick Craver
Guess I can't... I was under the impression it was solely for backward compatibility, but the ASP.NET 3.5 documentation lists it without mentioning this.
Bryan