有什么方法可以HttpContext.Current.Request.Url.Host
一键HttpContext.Current.Request.ApplicationPath
通话吗?
像“完整的应用程序网址”之类的东西?
编辑:澄清-我需要的是[]中的部分:
http://[www.mysite.com/mywebapp]/Pages/Default.aspx
我只是出于好奇而问。
编辑 2:感谢所有回复,但没有一个是我正在寻找的。仅供参考,我以这种方式解决了问题(但我仍然想知道是否有更顺畅的方式):
public string GetWebAppRoot()
{
if(HttpContext.Current.Request.ApplicationPath == "/")
return "http://" + HttpContext.Current.Request.Url.Host;
else
return "http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath;
}