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