文档视界 最新最全的文档下载
当前位置:文档视界 › 课题_asp,net中获取网站根目录和物理路径的方法

课题_asp,net中获取网站根目录和物理路径的方法

课题_asp,net中获取网站根目录和物理路径的方法

https://www.docsj.com/doc/0c14944168.html,中获取网站根目录和物理路径的方法

///

/// 取得网站的根目录的URL

///

///

public static string GetRootURI()

{

string AppPath = "";

Context Current = Context.Current;

Request Req;

if (Current != null)

{

Req = Current.Request;

string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority);

if (Req.ApplicationPath == null || Req.ApplicationPath == "/")

//直接安装在Web 站点

AppPath = UrlAuthority;

else

//安装在虚拟子目录下

AppPath = UrlAuthority + Req.ApplicationPath;

}

return AppPath;

}

///

/// 取得网站的根目录的URL

///

///

///

public static string GetRootURI(Request Req)

{

string AppPath = "";

if(Req != null)

{

string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority);

if (Req.ApplicationPath == null || Req.ApplicationPath == "/")

//直接安装在Web 站点

AppPath = UrlAuthority;

else

//安装在虚拟子目录下

AppPath = UrlAuthority + Req.ApplicationPath;

}

return AppPath;

}

///

/// 取得网站根目录的物理路径

///

///

public static string GetRootPath()

{

string AppPath = "";

Context Current = Context.Current;

if (Current != null)

{

AppPath = Current.Server.MapPath("~");

}

else

{

AppPath = AppDomain.CurrentDomain.BaseDirectory;

if (Regex.Match(AppPath, @"\\$", https://www.docsj.com/doc/0c14944168.html,piled).Success)

AppPath = AppPath.Substring(0, AppPath.Length - 1);

}

return AppPath;

}

相关文档