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

后端 未结 14 1477
庸人自扰
庸人自扰 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:31

    string baseUrl = Request.Url.GetLeftPart(UriPartial.Authority);
    

    Uri::GetLeftPart Method:

    The GetLeftPart method returns a string containing the leftmost portion of the URI string, ending with the portion specified by part.

    UriPartial Enumeration:

    The scheme and authority segments of the URI.

提交回复
热议问题