To redirect web traffic with Cloudflare and ASP.NET first enable IP Geolocation in CloudFlare dashboard:

Redirect web traffic with Cloudflare and ASP.NET

Related article:
http://netjunky.net/redirect-web-traffic-based-on-country-origin/

To learn more about Cloudflare visit there website:
https://www.cloudflare.com/overview

Once enabled, Cloudflare will then add a header called “CF-IPCountry” to all requests to your website.
In your ASP.NET website code capture that header and redirect traffic.

This can be done on single page or globally in global.asax file.

Code example:

if (Request.Headers.AllKeys.Contains("CF-IPCountry"))
{
    Response.Write(Request.Headers["CF-IPCountry"]);
}

Read header and save result in session to use it globally.
Add this code snippet to your global.asax file:

protected void Session_Start(object sender, EventArgs e)
{
   if (Request.Headers.AllKeys.Contains("CF-IPCountry"))
   {
      Session["language"] = Request.Headers["CF-IPCountry"].ToString();
   }
}

That’s all folks!

 

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!