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

Get IP Address with c#

5.Developement 2020. 9. 4. 10:24
    public static string GetIPAddress(string hostName)
        {
            var host = Dns.GetHostEntry(Dns.GetHostName());
            return (from ip in host.AddressList where ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork select ip.ToString()).FirstOrDefault();
        }

 

'5.Developement' 카테고리의 다른 글

Java Script - 글자수 제한  (0) 2019.09.25
posted by Keep It Simple Stupid