IIS7集成模式下,Application_Start下的HttpContext.Current如何处理?
protected void Application_Start(Object sender, EventArgs e)
{
...
if (!LicenseKeyInfoProvider.IsFeatureAvailable(UrlHelper.GetCurrentDomain(), FeatureEnum.Gzip))
...
}
public static string GetCurrentDomain()
{
if (HttpContext.Current == null)
{
return null;
}
if (HttpContext.Current.Request == null)
{
return null;
}
string string1 = HttpContext.Current.Request.Url.Host;
char[] charArray1 = new char[] { '/' };
return string1.Trim(charArray1);
}
iis6下或iis经典模式下是可以,一调到iis7集成模式就出错显示:
Server Error in '/' Application.
Request is not available in this context
查阅资料说集成模式下 Application_Start内不能用HttpContext.Current,哪我不知不用这个,我应该用什么了来代替上面的功能。
------解决方案--------------------System.Web.Hosting.HostingEnvironment.MapPath