I know in Asp.net MVC controller, we can access the application like this:
HttpContext.Application["AppVar"]
But in the Web api controller, there is no HttpContext, how to access the application Object then?
Join Stack Overflow to learn, share knowledge, and build your career.
I know in Asp.net MVC controller, we can access the application like this:
HttpContext.Application["AppVar"]
But in the Web api controller, there is no HttpContext, how to access the application Object then?
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.
HttpContext.Current.Application["AppVar"].
object context;
if (Request.Properties.TryGetValue("MS_HttpContext", out context))
{
var application= ((HttpContextBase)context).Application;
}
you can get HttpContext object from Request.Propertiies