0
votes

I have ASP.NET application (not MVC), with WEPAPI controllers.

we are using these controllers to share data between asp pages using ajax request.

when i logged into the system, i store the username in a session, but while i trying to check the value of this session in the controller, its value i null regardless if user is logged in or not.

HttpContext.Current.Session["Username"] = "admin";

How can i use the same session between controller and asp.net page?

1
An API shouldn't change its responses based on a session. Try rewriting it to something stateless and require the needed information in the request. - Christian Gollhardt

1 Answers

1
votes

ASP.NET Web API does not support sessions out of the box. As in your case ,if you are running your ASP.NET Web API within the ASP.NET run time you can enable session support globally by adding below in the Global.asax

protected void Application_PostAuthorizeRequest() 
{  

HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);

}