webapi 使用session 需要现在Global.asaxc初始化:

   public override void Init()
        {
            this.PostAuthenticateRequest += (sender, e) => HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);
            base.Init();
        }

使用:

ttpContext.Current.Session["token"] ="session"

初始化之后可以用上下文httpcontent取到前台传来的参数:

string TestStr = HttpContext.Current.Request.Form["Name"];

 

设置token过期时间  //这里我设置了但是好像没有生效  时间过了仍然存在  需要后面再研究

 

posted on 2018-12-26 11:53  FL0528  阅读(77)  评论(0)    收藏  举报