WebApi中使用session

webapi默认是不支持session的,要通过一些手动配置来开启Session功能

在Global.asax里添加:

导入命名空间:

using System.Web.SessionState;
public class WebApiApplication : System.Web.HttpApplication
    {
        public override void Init()
        {
            this.PostAuthenticateRequest += (sender, e) => HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);
            base.Init();
        }
原文地址:https://www.cnblogs.com/Williamls/p/9378739.html