.NET - Get protocol, host, and port

后端 未结 7 941
情歌与酒
情歌与酒 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:23

    A more structured way to get this is to use UriBuilder. This avoids direct string manipulation.

    var builder = new UriBuilder(Request.Url.Scheme, Request.Url.Host, Request.Url.Port);
    

提交回复
热议问题