webapi中session为null的解决方案

Posted 逻辑思维-质变

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了webapi中session为null的解决方案相关的知识,希望对你有一定的参考价值。

Session  webapi中session为null的解决方案

在Global.asax里添加:开启Session功能(默认是不开启)

重写init方法


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

以上是关于webapi中session为null的解决方案的主要内容,如果未能解决你的问题,请参考以下文章