Serenity Serenity - 10 months ago 55
ASP.NET (C#) Question

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

Let's say "" 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


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

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