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         }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM