獲取根目錄的URL例如http://localhost:51898
來源:懂視網
責編:小采
時間:2020-11-27 22:40:08
獲取根目錄的URL例如http://localhost:51898
獲取根目錄的URL例如http://localhost:51898: 代碼如下:public static string GetRootURI() { string AppPath = ; HttpContext HttpCurrent = HttpContext.Current; HttpRequest Req; if (HttpCurrent != null) { Req = HttpCurrent.Reques
導讀獲取根目錄的URL例如http://localhost:51898: 代碼如下:public static string GetRootURI() { string AppPath = ; HttpContext HttpCurrent = HttpContext.Current; HttpRequest Req; if (HttpCurrent != null) { Req = HttpCurrent.Reques

代碼如下:
public static string GetRootURI()
{
string AppPath = "";
HttpContext HttpCurrent = HttpContext.Current;
HttpRequest Req;
if (HttpCurrent != null)
{
Req = HttpCurrent.Request; string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority);
if (Req.ApplicationPath == null || Req.ApplicationPath == "/")
//直接安裝在 Web 站點
AppPath = UrlAuthority;
else
//安裝在虛擬子目錄下
AppPath = UrlAuthority + Req.ApplicationPath;
}
return AppPath;
}
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
獲取根目錄的URL例如http://localhost:51898
獲取根目錄的URL例如http://localhost:51898: 代碼如下:public static string GetRootURI() { string AppPath = ; HttpContext HttpCurrent = HttpContext.Current; HttpRequest Req; if (HttpCurrent != null) { Req = HttpCurrent.Reques