【发布时间】:2013-11-02 05:26:09
【问题描述】:
我正在考虑实现类似于静态 SessionHelper 类的东西,我想在 Session 中保留一些数据。
但似乎不可能在 Controller 类之外使用 Session 对象。对吧?
或者可能是我错了...即这个链接是解决方案吗ASP.NET MVC - How to access Session data in places other than Controller and Views
请告诉我!
无论如何,现在我无法引用该类中的 Session 对象,该类位于 Models 文件夹中。
public static class SessionHelper
{
public static bool ShowSuccessPopup
{
get
{
if (Session["ShowSuccessPopup"] == null)
{
Session["ShowSuccessPopup"] = false;
return false;
}
else
{
var result = (bool)Session["ShowSuccessPopup"].ToString();
return result;
}
}
set {Session["ShowSuccessPopup"] = value; }
}
}
【问题讨论】:
标签: c# .net asp.net-mvc asp.net-mvc-4 session