BaseURL 가져오기

카테고리 없음 2021. 12. 23. 09:19

.Net4.0 c#

   public static string GetBaseUrl()
        {
            string protocol;

            if (HttpContext.Current.Request.IsSecureConnection)
                protocol = "https";
            else
                protocol = "http";

            System.Text.StringBuilder uri = new System.Text.StringBuilder(protocol + "://");

            string hostname = HttpContext.Current.Request.Url.Host;
            uri.Append(hostname);
            int port = HttpContext.Current.Request.Url.Port;
            if (port != 80 && port != 443)
            {
                uri.Append(":");
                uri.Append(port.ToString());
            }
            return uri.ToString();
        }

 

posted by Keep It Simple Stupid