【发布时间】:2012-06-28 18:29:06
【问题描述】:
我正在尝试在 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) 中的区域性。这对自定义错误视图很有帮助。
我感觉自己走错了路,所以如果有人能指出我正确的方向,我将不胜感激。
【问题讨论】:
标签: asp.net-mvc session variables