首页 > Web开发 > 详细

asp.net 获取网站根地址

时间:2018-12-01 21:21:28      阅读:219      评论:0      收藏:0      [点我收藏+]
 1 public static string GetSiteRoot()
 2         {
 3             string port = System.Web.HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
 4             if (port == null || port == "80" || port == "443")
 5             {
 6                 port = "";
 7             }
 8             else
 9             {
10                 port = ":" + port;
11             }
12             string protocol = System.Web.HttpContext.Current.Request.ServerVariables["SERVER_PORT_SECURE"];
13             if (protocol == null || protocol == "0")
14             {
15                 protocol = "http://";
16             }
17             else
18             {
19                 protocol = "https://";
20             }
21             string sOut = protocol + System.Web.HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + port + System.Web.HttpContext.Current.Request.ApplicationPath;
22             if (sOut.EndsWith("/"))
23             {
24                 sOut = sOut.Substring(0, sOut.Length - 1);
25             }
26             return sOut;
27         }

 

asp.net 获取网站根地址

原文:https://www.cnblogs.com/sjzww/p/10050882.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!