1、WebApi默认是不开启Session的,如果需要开启需要在 Global.asax 文件中添加如下配置
public override void Init()
{
//注册事件
this.AuthenticateRequest += WebApiApplication_AuthenticateRequest;
base.Init();
}
//开启session支持
void WebApiApplication_AuthenticateRequest(object sender, EventArgs e)
{
//启用 webapi 支持session 会话
HttpContext.Current.SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.Required);
}
2、在Web.config中配置sessionState节点代码如下:
<configuration>
<system.web>
<sessionState mode="InProc" timeout="120"/>
</system.web>
</configuration>
到此就结束了!