需要在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);
}