且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 URL 获取主机域?

更新时间:2023-02-26 10:15:20

您可以使用 Request 对象或 Uri 对象来获取 url 的主机.

You can use Request object or Uri object to get host of url.

使用 Request.Url

string host = Request.Url.Host;

使用 Uri

Uri myUri = new Uri("http://www.contoso.com:8080/");   
string host = myUri.Host;  // host is "www.contoso.com"