如何在ASP.NET/C#中检查URL的顶级域?

Ser*_*ity 2 c# asp.net url

假设"www.mysite.fr/home"是URL ..现在如何从中获取"fr"?只是"fr"

实际上我想要做的是在检测到访问者的国家后在运行时更改主页.是的,我可以使用countryCode变量,这是在其他一些类中,但是thot可能是我可以这样做只是..只是想尝试..logic基本上是: -

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


if(its "in")
{
//apply masterpage 2
}
Run Code Online (Sandbox Code Playgroud)

可能吗 ?无论如何,这将是正确的方式?将包含CountryCode变量的类作为实用程序类,并在我的新类中使用该变量

要么

从URL中取"fr"或"in"这个值?我该怎么做呢 ?可能吗?

Mar*_*ade 6

 if (Request.Url.Host.ToLower().EndsWith(".fr"))
  {
    ...
  }
Run Code Online (Sandbox Code Playgroud)