【发布时间】:2013-12-06 23:12:13
【问题描述】:
几个月来我一直面临这个问题,我已经阅读了几乎所有关于此的内容并实施了大多数解决方案,但仍然没有任何改变。我不知道我在哪里犯错了。
我正在使用自定义 SessionManager 类在我的 ASP.net CMS 网站的管理面板中轻松获取/设置值到 Session。当用户登录时,我将用户数据存储到Session,然后在 Admin.master 页面中读取以检查用户是否已登录。在不同的服务器和本地主机上,SessionManager.CurrentUser 值随机为空,有时为 2分钟有时登录后 20 分钟,无论页面是否空闲。我所有的网站都有同样的问题。
我的 SessionManager.cs 是
public class SessionManager
{
public SessionManager() { }
public static User CurrentUser
{
get { return (User)HttpContext.Current.Session["crntUsr"]; }
set { HttpContext.Current.Session["crntUsr"] = value; }
}
public static string CurrentAdminLanguage
{
get
{
if (HttpContext.Current.Session["crntLang"] == null) HttpContext.Current.Session["crntLang"] = SiteSettings.DefaultLanguage;
return HttpContext.Current.Session["crntLang"].ToString();
}
set
{
HttpContext.Current.Session["crntLang"] = value;
}
}
}
注意:用户类是 [Serializable]
在 Admin.master Page_Load 中
if (SessionManager.CurrentUser == null) Response.Redirect("../login");
在 web.config 中
<system.web>
<sessionState mode="InProc" customProvider="DefaultSessionProvider" cookieless="UseCookies" regenerateExpiredSessionId="true" timeout="60"/>
<machineKey validationKey="CC0...F80" decryptionKey="8BF...1B5" validation="SHA1" decryption="AES"/>
<authentication mode="Forms">
<forms loginUrl="~/login" timeout="60" slidingExpiration="true" cookieless="UseCookies" />
</authentication>
<system.webServer>
<modules>
<remove name="Session"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
</modules>
我真的没有更多的想法来解决这个问题。请帮忙:(
【问题讨论】:
-
在这里尝试我的解决方案:stackoverflow.com/questions/24868515/…