要在webApi里面使用Session必须在Global.asax插入
public override void Init() { this.PostAuthenticateRequest += (sender, e) => HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required); base.Init(); }
WebAPI中启用Session
本文介绍如何在WebAPI中配置SessionStateBehavior为Required,确保在WebAPI请求验证后,能够使用Session状态。此方法适用于需要在API调用中保持会话状态的应用场景。
要在webApi里面使用Session必须在Global.asax插入
public override void Init() { this.PostAuthenticateRequest += (sender, e) => HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required); base.Init(); }
转载于:https://www.cnblogs.com/Linyb/p/4528140.html

被折叠的 条评论
为什么被折叠?