1 /// <summary> 2 /// 得到当前网站的根地址 3 /// </summary> 4 /// <returns></returns> 5 protected string GetRootPath() 6 { 7 // 是否为SSL认证站点 8 string secure = HttpContext.Current.Request.ServerVariables["HTTPS"]; 9 string httpProtocol = (secure == "on" ? "https://" : "http://"); 10 // 服务器名称 11 string serverName = HttpContext.Current.Request.ServerVariables["Server_Name"]; 12 string port = HttpContext.Current.Request.ServerVariables["SERVER_PORT"]; 13 // 应用服务名称 14 string applicationName = HttpContext.Current.Request.ApplicationPath; 15 return httpProtocol + serverName + (port.Length > 0 ? ":" + port : string.Empty) + applicationName; 16 }
原文:http://www.cnblogs.com/wangjingblogs/p/3799007.html