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过期时间 //这里我设置了但是好像没有生效 时间过了仍然存在 需要后面再研究

浙公网安备 33010602011771号