Request object in Application
We currently use this line of code to get the current applications url in the Application_Start event.
string sApplicationURL = HttpContext.Current.Request.Url.Scheme + "://"
+ HttpContext.Current.Request.Url.Authority
+ HttpContext.Current.Request.ApplicationPath;
I just recently found out that in IIS7.0 the Request object is no longer available when the Application_Start event is fired.
Is there another way to get the current applications url without using the Request object?
Thanks
Have a look at this: http://mvolo.com/blogs/serverside/archive/2007/11/10/Integrated-mode-Request-is-not-available-in-this-context-in-Application_5F00_Start.aspx
In summary, the error occurs because the Request context is not longer available to the Application_Start event. This blog states two choices to deal with this error:
1) Change your code to work w/o Request, or 2) Modify your application to run in Classic Mode (not recommended).
To get the ApplicationPath, use HttpRuntime.AppDomainAppVirtualPath .
Microsoft has a all-in-one article on all breaking changes including this one,
http://learn.iis.net/page.aspx/381/aspnet-20-breaking-changes-on-iis-70/
Yes, its content somehow comes from http://mvolo.com (and the reason is simple).
链接地址: http://www.djcxy.com/p/67970.html下一篇: 申请中的请求对象