2的WebAPI路由属性使会话状态 [英] WebAPI 2 attribute routing enable session state
本文介绍了2的WebAPI路由属性使会话状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们想出如何使会话状态与样品这里
We figured out how to enable session state with webapi Sample here
现在我们的WebAPI 2属性的路由,所以我们不再有路由对象注入自定义的处理器。
Now we have WebApi 2 attribute routing, so we no longer have route object to inject custom handler.
有没有启用会话状态,属性的任何路由?
推荐答案
作为评论前面提到你需要
As mentioned in a comment earlier you need to
此加入的Global.asax
protected void Application_PostAuthorizeRequest()
{
System.Web.HttpContext.Current.SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.Required);
}
然后,你可以通过访问会话:
Then you could access the session through:
HttpContext.Current.Session
这篇关于2的WebAPI路由属性使会话状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文