12,162
社区成员
发帖
与我相关
我的任务
分享
public class TestController : ApiController
{
[HttpGet]
public dynamic Get()
{
HttpContext.Current.Session["Key"] = "112233";
return "123";
}
[HttpGet]
public string Post()
{
var q = HttpContext.Current.Session["Key"].ToString();
return q;
}
}
[/quote]好蛋疼。。。 看来我还得自己测试解决了。 非常感谢您的耐心解答。public class TestController : ApiController
{
[HttpGet]
public dynamic Get()
{
HttpContext.Current.Session["Key"] = "112233";
return "123";
}
[HttpGet]
public string Post()
{
var q = HttpContext.Current.Session["Key"].ToString();
return q;
}
}
是的。 你的 action1和 action2 所在的controller都是继承自 apicontroller吗?
应该不会出现你说的这个问题,是不是你的 HttpContext就是null哦
你的 action1和 action2 所在的controller都是继承自 apicontroller吗?
webapi默认是不支持session的吧,要通过一些手动配置来开启,可上网百度
在Global.asax里添加:开启Session功能http://blog.csdn.net/kmguo/article/details/23525409 参考http://stackoverflow.com/questions/9594229/accessing-session-using-asp-net-web-apipublic class WebApiApplication : System.Web.HttpApplication { public override void Init() { this.PostAuthenticateRequest += (sender, e) => HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required); base.Init(); } }
webapi默认是不支持session的吧,要通过一些手动配置来开启,可上网百度
public class WebApiApplication : System.Web.HttpApplication
{
public override void Init()
{
this.PostAuthenticateRequest += (sender, e) => HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);
base.Init();
}
}
http://blog.csdn.net/kmguo/article/details/23525409
参考http://stackoverflow.com/questions/9594229/accessing-session-using-asp-net-web-api