码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-06-28 11:04:34      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   get   name   

 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         }

 

C#获取当前站点的根地址,布布扣,bubuko.com

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

标签:style   blog   http   color   get   name   

原文地址:http://www.cnblogs.com/wangjingblogs/p/3799007.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!