服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服务器之家 - 编程语言 - ASP.NET教程 - 获取根目录的URL例如http://localhost:51898

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

2019-11-28 12:49ASP.NET教程网 ASP.NET教程

这篇文章主要介绍了获取根目录的URL的方法,需要的朋友可以参考下

代码如下:

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; 

延伸 · 阅读

精彩推荐