this.Request.Url.GetLeftPart(UriPartial.Authority)
可以獲得http://www.baidu.com,無論是什么請求。另外,根據(jù)不同的UriPartial枚舉值,可以得到path、QueryString等字符串。
一下內(nèi)容來源:http://www./html/2009-03/21_932_00.html
---------------------------------------------------------------------
獲取網(wǎng)站根目錄的urli源代碼
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;
}