如何用c#获得当前站点的根路径

 

        public string GetRootPath()
        
{
            
// 是否为SSL认证站点
            string secure = HttpContext.Current.Request.ServerVariables["HTTPS"];
            
string httpProtocol = (secure == "on" ? "https://" : "http://");

            
// 服务器名称
            string serverName = HttpContext.Current.Request.ServerVariables["Server_Name"];
            string port = HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
               
            
// 应用服务名称
            string applicationName = HttpContext.Current.Request.ApplicationPath;

            
return httpProtocol + serverName + (port.Length > 0 ? ":" + port : string.Empty) + applicationName;
        }
posted @ 2005-12-07 13:40  Elaine Shi  阅读(4059)  评论(5编辑  收藏  举报