В настоящее время мой код выглядит следующим образом
Код: Выделить всё
string CountryName = "";
var Country = HttpContext.Current.Response.Cookies["Country"];
Country.Expires = DateTime.Now.AddDays(365);
var ip = HttpContext.Current.Request.UserHostAddress;
if (!string.IsNullOrEmpty(ip) && ip != null && ip != "127.0.0.1")
{
using (var client = new WebServiceClient(xxxxx, "xxxxxxxx"))
{
var IpCountry = client.Country(ip);
CountryName = IpCountry.Country.Name;
}
switch (CountryName)
{
case "Denmark":
if (Country.Value != CountryName)
{
Country.Value = CountryName;
HttpContext.Current.Response.Redirect("/");
}
break;
case "United Kingdom":
if (Country.Value != CountryName)
{
Country.Value = CountryName;
HttpContext.Current.Response.Redirect("/en");
}
break;
case "Germany":
if (Country.Value != CountryName)
{
Country.Value = CountryName;
HttpContext.Current.Response.Redirect("/de");
}
break;
case "Sweden":
if (Country.Value != CountryName)
{
Country.Value = CountryName;
HttpContext.Current.Response.Redirect("/se");
}
break;
case "Norway":
if (Country.Value != CountryName)
{
Country.Value = CountryName;
HttpContext.Current.Response.Redirect("/no");
}
break;
default:
if (Country.Value != CountryName)
{
Country.Value = CountryName;
//HttpContext.Current.Response.Redirect("http://www.google.com");
}
break;
}
}
else if (loadedArgs.pageview.Area.ID != 2)
{
HttpContext.Current.Response.Redirect("/choose-country");
}