【发布时间】:2012-05-23 03:30:13
【问题描述】:
在 Global.asax.cs 的 Application_Start 中,我正在尝试使用以下方法获取当前应用程序路径:
var virtualPath = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)
+ HttpRuntime.AppDomainAppVirtualPath;
这将返回例如:@987654321@
然后我将使用此 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 ”。
我知道这个帖子:Request is not available in this context
但是,我想知道是否有人知道如何在不将项目更改为以经典模式运行的情况下执行上述操作。
【问题讨论】:
-
另外,这似乎与如何在 Global.aspx 的 Application_Start 中获取完整的主机名 + 端口号重复?问题:stackoverflow.com/questions/4243270/…
标签: asp.net asp.net-mvc iis iis-7