欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

获取根目录的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;
}