How can I get the root domain URI in ASP.NET?

后端 未结 14 1463
庸人自扰
庸人自扰 2020-12-12 16:15

Let\'s say I\'m hosting a website at http://www.foobar.com.

Is there a way I can programmatically ascertain \"http://www.foobar.com/\" in my code behind (i.e. witho

14条回答
  •  无人及你
    2020-12-12 16:40

    string host = Request.Url.Host;
    Regex domainReg = new Regex("([^.]+\\.[^.]+)$");
    HttpCookie cookie = new HttpCookie(cookieName, "true");
    if (domainReg.IsMatch(host))
    {
      cookieDomain = domainReg.Match(host).Groups[1].Value;                                
    }
    

提交回复
热议问题