/ Published in: C#
Will return the host name that the site is running on. Example:
http://mysite.com or http://myspecialsite.com:102
Expand |
Embed | Plain Text
public static string ServerHostName() { string port = HttpContext.Current.Request.ServerVariables["SERVER_PORT"]; if (port == null || port == "80" || port == "443") { port = ""; } else { port = ":" + port; } string protocol = HttpContext.Current.Request.ServerVariables["SERVER_PORT_SECURE"]; if (protocol == null || protocol == "0") { protocol = "http://"; } else { protocol = "https://"; } return protocol + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + port; }
You need to login to post a comment.
