Accessing Session Using ASP.NET Web API

前端 未结 13 1127
谎友^
谎友^ 2020-11-22 04:32

I realize session and REST don\'t exactly go hand in hand but is it not possible to access session state using the new Web API? HttpContext.Current.Session is a

13条回答
  •  孤城傲影
    2020-11-22 05:12

    one thing need to mention on @LachlanB 's answer.

    protected void Application_PostAuthorizeRequest()
        {
            if (IsWebApiRequest())
            {
                HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);
            }
        }
    

    If you omit the line if (IsWebApiRequest())

    The whole site will have page loading slowness issue if your site is mixed with web form pages.

提交回复
热议问题