【发布时间】:2014-03-12 14:33:50
【问题描述】:
我知道 REST 应该是无状态的。
我的 Web Api 与我的 MVC 网站在同一个项目中。如何在他们之间共享会话?
我正在尝试使用 Web Api 2 的优点并使用 Ajax,而不是构建 RESTful API。
【问题讨论】:
标签: c# asp.net-web-api
我知道 REST 应该是无状态的。
我的 Web Api 与我的 MVC 网站在同一个项目中。如何在他们之间共享会话?
我正在尝试使用 Web Api 2 的优点并使用 Ajax,而不是构建 RESTful API。
【问题讨论】:
标签: c# asp.net-web-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);
}
【讨论】: