首页 > 编程 > .NET > 正文

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

2024-07-10 13:26:58
字体:
来源:转载
供稿:网友

复制代码 代码如下:


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 == "http://www.vevb.com/")
//直接安装在 Web 站点
AppPath = UrlAuthority;
else
//安装在虚拟子目录下
AppPath = UrlAuthority + Req.ApplicationPath;
}
return AppPath;
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表