【问题标题】:HttpContext.Current.Session returns null when used in a utility class (ASP.NET MVC)HttpContext.Current.Session 在实用程序类 (ASP.NET MVC) 中使用时返回 null
【发布时间】:2014-05-14 04:56:21
【问题描述】:

所以我创建了一个静态扩展类来为 DateTime 对象提供扩展方法。我按照本教程来解决时区问题:http://www.prideparrot.com/blog/archive/2011/9/how_to_display_dates_and_times_in_clients_timezone

问题是我的实用程序类不在控制器中并且 System.Web.HttpContext.Current.Session 为空,我不想每次都将上下文作为参数传递,因为我需要使用它也在不同的位置。

有没有办法将会话传递给外部班级?

【问题讨论】:

    标签: asp.net-mvc session null httpcontext


    【解决方案1】:

    尝试在您的代码中实现此接口。它适用于处理程序。

    System.Web.SessionState.IRequiresSessionState 
    

    【讨论】:

    • 这还不够,这里的图片还有其他内容。
    猜你喜欢
    • 2019-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    • 2010-11-22
    • 2015-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多