MVC 3中的强类型会话变量

| 我正在尝试在MVC 3应用程序中设置会话包装。这篇文章给出了我想做的一般想法:http://weblogs.asp.net/cstewart/archive/2008/01/09/strongly-typed-session-in-asp-net.aspx 但是,访问会话时,会话始终为空。该类在控制器外部,并且当前正在控制器外部访问该变量。 这是课程:
public sealed class SessionManager : IRequiresSessionState
{
    private const string CurrentCultureKey = \"CurrentCulture\";
    public static Culture CurrentCulture
    {
        get
        {
            if (null != HttpContext.Current.Session[CurrentCultureKey])
                return (Culture)HttpContext.Current.Session[CurrentCultureKey];

            return Culture.En;
        }
        set
        {
            if (HttpContext.Current.Session != null)
            HttpContext.Current.Session[CurrentCultureKey] = value;
        }
    }
}
我添加了IRequiresSessionState,但这似乎也不起作用。 如果我在会话中想要跟踪的地址(/ En / Controller / Action)中没有区域性,我将使用此变量来帮助自定义路由。这将有助于自定义错误视图。 我有种感觉,我走错了路,所以如果有人能指出我正确的方向,我将不胜感激。     
已邀请:
        因此,最终我没有找到在控制器操作方法之外访问会话的方法。相反,我将值存储在cookie中,这更有意义。 但是,如果用户关闭了Cookie,并且网站上发生了错误,则当前会将它们转发到默认语言。如果没有cookie,我可能必须将此信息存储在数据库中,或者存储具有唯一ID的缓存项。     

要回复问题请先登录注册