WebAPI 2 属性路由启用会话状态 [英] WebAPI 2 attribute routing enable session state
本文介绍了WebAPI 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.
有没有办法通过属性路由启用会话状态?
推荐答案
您需要将此添加到 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
这篇关于WebAPI 2 属性路由启用会话状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文