I know in Asp.net MVC controller, we can access the application like this:
我知道在Asp.net MVC控制器中,我们可以像这样访问应用程序:
HttpContext.Application["AppVar"]
But in the Web api controller, there is no HttpContext, how to access the application Object then?
但是在Web api控制器中,没有HttpContext,如何访问应用程序对象呢?
2 个解决方案
#1
12
the http context still exists and it's a core component of ASP.Net. how you gain access to it is the issue at hand.
http上下文仍然存在,它是ASP.Net的核心组件。如何获得访问权限是手头的问题。
HttpContext.Current.Application["AppVar"].
#2
0
object context;
if (Request.Properties.TryGetValue("MS_HttpContext", out context))
{
var application= ((HttpContextBase)context).Application;
}
you can get HttpContext object from Request.Propertiies
你可以从Request.Propertiies获取HttpContext对象
#1
12
the http context still exists and it's a core component of ASP.Net. how you gain access to it is the issue at hand.
http上下文仍然存在,它是ASP.Net的核心组件。如何获得访问权限是手头的问题。
HttpContext.Current.Application["AppVar"].
#2
0
object context;
if (Request.Properties.TryGetValue("MS_HttpContext", out context))
{
var application= ((HttpContextBase)context).Application;
}
you can get HttpContext object from Request.Propertiies
你可以从Request.Propertiies获取HttpContext对象