Serenity Serenity - 1 month ago 5
ASP.NET (C#) Question

How do I check for a URL's top-level domain in ASP.NET/C#?

Let's say "www.mysite.fr/home" is the URL ..Now how do I fetch "fr" out of this ? JUST "fr"

actually what I am trying to do is change masterpages at runtime after detecting a visitor's country..Yes I can use the countryCode variable which is there in some other class but thot may be I can do it like this only..just wanted to try..logic basically is:-

if(its "fr")
{
//apply masterpage 1
}


if(its "in")
{
//apply masterpage 2
}


Is it possible ? What will be the right way anyway ? Making that class that contains CountryCode variable as a utility class and using the variable from there in my new class

OR

fetch this value "fr" or "in" off the URL ?? How do I do this ? Is it possible?

Answer
 if (Request.Url.Host.ToLower().EndsWith(".fr"))
  {
    ...
  }