我的Global.asax.cs的的Application_Start里面,我试图用得到当前应用程序路径:得到当前的应用程序虚拟路径在ASP.Net
var virtualPath = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)
+ HttpRuntime.AppDomainAppVirtualPath;
这将返回例如:http://localhost:99/MySite/
我会然后使用这个URL并执行以下操作:
var pageToHit = virtualPath + Pages\MyOtherPage.aspx
var client = new WebClient();
client.DownloadData(dummyPageUrl);
这一切都很好,当我运行IIS 6中的项目或在Visual Studio内置web服务器,然而,事情发生在IIS 7中疯狂,因为我得到一个“System.Web.HttpException:请求在此上下文中不可用”。
我知道这个线程:Request is not available in this context
不过,我想知道是否有人对如何做上述不改变该项目在经典模式下运行的任何想法。
此外,这似乎是如何获得完整的主机名+端口号的副本中Global.aspx的的Application_Start?问题:http://stackoverflow.com/questions/4243270/how-to-get-full-host-name-port-number-in-application-start-of-global-aspx – JamieSee