【问题标题】:ServiceStack - System.Web.HttpContext.Current.Session is nullServiceStack - System.Web.HttpContext.Current.Session 为空
【发布时间】:2021-05-30 23:38:49
【问题描述】:

我有与 ServiceStack API 集成的遗留 .net mvc 应用程序,我需要从 ServiceStack API 获取/设置会话值,以便与遗留系统通信以确保正常工作。我探索了 ServiceStack 文档/其他材料中可用的多个选项,但在我的情况下似乎没有任何效果。

启用会话功能:

Plugins.Add(new SessionFeature());

尝试直接使用:

HttpContext.Current.Session

另一种方式:

var req = (HttpRequest)base.RequestContext.Get<IHttpRequest>().OriginalRequest;
var session = req.RequestContext.HttpContext.Session;

但它们似乎都不起作用。

reference

【问题讨论】:

    标签: asp.net-mvc session servicestack session-cookies session-state


    【解决方案1】:

    ServiceStack Sessions 是一个完全独立的实现,不依赖或耦合到 ASP.NET 的会话。

    要在 ServiceStack 请求中启用对 ASP.NET 会话的访问,您需要使用 IRequiresSessionState 接口装饰其 IHttpHandler,如 Enable ASP.NET Sessions 文档所述。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多