.NET - Get protocol, host, and port

后端 未结 7 1010
情歌与酒
情歌与酒 2020-11-28 19:18

Is there a simple way in .NET to quickly get the current protocol, host, and port? For example, if I\'m on the following URL:

http://www.mywebsite.com:80/pages

7条回答
  •  余生分开走
    2020-11-28 19:24

    The following (C#) code should do the trick

    Uri uri = new Uri("http://www.mywebsite.com:80/pages/page1.aspx");
    string requested = uri.Scheme + Uri.SchemeDelimiter + uri.Host + ":" + uri.Port;
    

提交回复
热议问题