获取根目录的URL例如http://localhost:51898
程序员文章站
2024-02-27 15:41:27
复制代码 代码如下: public static string getrooturi() { string apppath = ""; httpcontext httpcu...
复制代码 代码如下:
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;
}
上一篇: IIS7的应用程序池详细解析