12

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?

2 Answers 2

16

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"].
Sign up to request clarification or add additional context in comments.

1 Comment

This doesn't seem to work in Web API 2 ("HttpContext does not exist in the namespace "System.Web"...) so in this case, OP's question remains unanswered. Is there more information for Web API 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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.