码迷,mamicode.com
首页 > Web开发 > 详细

asp.net 获取网站根地址

时间:2018-12-01 22:10:53      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:request   system   sys   lse   ica   port   div   sub   roo   

 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 获取网站根地址

标签:request   system   sys   lse   ica   port   div   sub   roo   

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

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