0

I have defined a session variable in Api controller

HttpContext.Current.Session["_USBDocuments"] = folders;

Now, i want to access the session variable which is defined in api controller in the normal controller.

Is it possible to access like this? If it is possible then what is the way to access it?

Thank You.

Bhushan Firake
  • 9,338
  • 5
  • 44
  • 79

1 Answers1

0

By design, you are not supposed to use Session in Web API. It defeats the purpose of it being stateless. But if you still want to access Session in an Api Controller, you can add the following function in your Global.asax.cs file:

protected void Application_PostAuthorizeRequest()
{
    HttpContext.Current.SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.Required);
}
RushabhG
  • 352
  • 3
  • 11