Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable session in Web Api 2 [duplicate]

I know REST should be stateless.

My Web Api is at the same project of my MVC Website. How can I share the session between them?

I'm trying to use the goodies of Web Api 2 and work with Ajax rather than build a RESTful API.

like image 507
hasser Avatar asked Mar 12 '14 14:03

hasser


1 Answers

stolen from this question

in global.asax add the following:

public override void Init()
{
    this.PostAuthenticateRequest += MvcApplication_PostAuthenticateRequest;
    base.Init();
}

void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e)
{
    System.Web.HttpContext.Current.SetSessionStateBehavior(
        SessionStateBehavior.Required);
}
like image 89
joelmdev Avatar answered Oct 11 '22 05:10

joelmdev