How to get full host name + port number in Application_Start of Global.aspx?

后端 未结 3 1681
梦谈多话
梦谈多话 2020-11-29 05:29

I tried

Uri uri = HttpContext.Current.Request.Url;
String host = uri.Scheme + Uri.SchemeDelimiter + uri.Host + \":\" + uri.Port;

and it wo

3条回答
  •  感动是毒
    2020-11-29 06:19

    Just answering this so if someone ever decides to actually search on this topic...

    This works on application start in any mode...

    typeof(HttpContext).GetField("_request", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(HttpContext.Current)
    

提交回复
热议问题