在Web Api 2中启用会话
我知道REST应该是无国籍的。
我的Web Api与我的MVC网站属于同一个项目。 我如何分享他们之间的会话?
我正在尝试使用Web Api 2的好东西并使用Ajax而不是构建RESTful API。
从这个问题中偷来的
在global.asax中添加以下内容:
public override void Init() { this.PostAuthenticateRequest += MvcApplication_PostAuthenticateRequest; base.Init(); } void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e) { System.Web.HttpContext.Current.SetSessionStateBehavior( SessionStateBehavior.Required); }