zl程序教程

您现在的位置是:首页 >  前端

当前栏目

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

HTTP 获取 url 根目录 localhost 例如
2023-06-13 09:15:17 时间
复制代码代码如下:

publicstaticstringGetRootURI()
{
stringAppPath="";
HttpContextHttpCurrent=HttpContext.Current;
HttpRequestReq;
if(HttpCurrent!=null)
{
Req=HttpCurrent.Request;

stringUrlAuthority=Req.Url.GetLeftPart(UriPartial.Authority);
if(Req.ApplicationPath==null||Req.ApplicationPath=="/")
//直接安装在Web站点
AppPath=UrlAuthority;
else
//安装在虚拟子目录下
AppPath=UrlAuthority+Req.ApplicationPath;
}
returnAppPath;
}