启用网页API 2届 [英] Enable session in Web Api 2

查看:107
本文介绍了启用网页API 2届的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道剩下的应该是无状态的。

I know REST should be stateless.

我的Web API是在我的MVC网站的同一个项目。我怎么可以分享他们之间的会话?

My Web Api is at the same project of my MVC Website. How can I share the session between them?

我试图用网页API 2的超值服务,并与阿贾克斯工作,而不是建立一个RESTful API。

I'm trying to use the goodies of Web Api 2 and work with Ajax rather than build a RESTful API.

推荐答案

从的这个问题

在Global.asax中添加以下内容:

in global.asax add the following:

public override void Init()
{
    this.PostAuthenticateRequest += MvcApplication_PostAuthenticateRequest;
    base.Init();
}

void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e)
{
    System.Web.HttpContext.Current.SetSessionStateBehavior(
        SessionStateBehavior.Required);
}

这篇关于启用网页API 2届的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆