需要在Global.asax中添加代码即可
public override void Init()
{
//注册事件
this.AuthenticateRequest += WebApiApplication_AuthenticateRequest;
base.Init();
}
void WebApiApplication_AuthenticateRequest(object sender, EventArgs e)
{
//启用 webapi 支持session 会话
HttpContext.Current.SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.Required);
}