龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > asp.net编程 >

获取根目录的URL例如http://localhost:51898

时间:2014-06-14 15:11来源:网络整理 作者:网络 点击:
分享到:
这篇文章主要介绍了获取根目录的URL的方法,需要的朋友可以参考下
代码如下:

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;
}
精彩图集

赞助商链接