/ Published in: C#
Will return the host name that the site is running on. Example:
`http://mysite.com` or `http://myspecialsite.com:102`
`http://mysite.com` or `http://myspecialsite.com:102`
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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; }