C#获取当前站点的根地址

 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         }

 

posted @ 2014-06-20 11:40  wangjj89621  阅读(3334)  评论(0编辑  收藏  举报