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

后端 未结 3 1682
梦谈多话
梦谈多话 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:27

    The accepted answer is good, but in most cases (if the first request is a HTTP Request) you should better use the Session_Start event, which is called once per user every 20 minutes or so (not sure how long the session is valid). Application_BeginRequest will be fired at every Request.

    public void Session_Start(Object source, EventArgs e)
    {
       //Request / Request.Url is available here :)
    }
    

提交回复
热议问题