7

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.

hasser
  • 1,066
  • 1
  • 13
  • 24

1 Answers1

15

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);
}
Community
  • 1
  • 1
joelmdev
  • 11,083
  • 10
  • 65
  • 89