C# Mvc 4在执行过程中退出文本会话
我在C# Mvc 4在执行过程中退出文本会话,c#,asp.net-mvc-4,session,ef-code-first,C#,Asp.net Mvc 4,Session,Ef Code First,我在mvc4中开发了一个网站,该网站使用代码优先实体框架。我在登录到我的站点时使用了HttpContext.GetOwinContext().sign HttpContext.GetOwinContext().SignIn(user, model.RememberMe); HttpContext.SetSession(WebConstants.SessionUser, user); 当我登录时,存储usersession。我有一个索引视图。在该视图上,我创建了六到七个菜单选项卡。第一次打开
mvc4
中开发了一个网站,该网站使用代码优先实体框架。我在登录到我的站点时使用了HttpContext.GetOwinContext().sign
HttpContext.GetOwinContext().SignIn(user, model.RememberMe);
HttpContext.SetSession(WebConstants.SessionUser, user);
当我登录时,存储user
session。我有一个索引
视图。在该视图上,我创建了六到七个菜单选项卡。第一次打开时,它会加载第一个菜单选项卡。加载时,它从表中获取一些数据并显示在视图中。所以每个选项卡都有一些数据。我已经创建了一个basecontroller
。在这个控制器中,我正在访问会话数据
这是我的basecontroller
protected Domain.ClientAgg.User GetUserContext()
{
return HttpContext.GetSession<SN.Domain.ClientAgg.User>(WebConstants.SessionUser);
}
protected string GetUserClientShortname()
{
return HttpContext.GetSession<SN.Application.DTO.UserContext>(WebConstants.SessionUser).Client.ShortName;
}
protected int GetUserClientId()
{
return HttpContext.GetSession<SN.Application.DTO.UserContext>(WebConstants.SessionUser).Client.Id;
}
protected SN.Application.DTO.UserContext GetClientUserContext()
{
return HttpContext.GetSession<SN.Application.DTO.UserContext>(WebConstants.SessionUser);
}
.....
......
......
protecteddomain.ClientAgg.User GetUserContext()
{
返回HttpContext.GetSession(WebConstants.SessionUser);
}
受保护的字符串GetUserClientShortname()
{
返回HttpContext.GetSession(WebConstants.SessionUser).Client.ShortName;
}
受保护的int-GetUserClientId()
{
返回HttpContext.GetSession(WebConstants.SessionUser).Client.Id;
}
受保护的SN.Application.DTO.UserContext GetClientUserContext()
{
返回HttpContext.GetSession(WebConstants.SessionUser);
}
.....
......
......
我使用这种方法从表中获取数据,并将其显示在选项卡视图中。这里我的问题是,如果我持续在这些选项卡之间导航,会话将过期。我认为如果当前进程正在执行,并且我单击了其他选项卡,那么此时执行进程中断,就会出现这个问题。有人能告诉我如何解决这个问题吗?请检查启动配置中的过期设置,例如:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
ExpireTimeSpan = TimeSpan.FromHours(4.0),
SlidingExpiration = true
});
您可以在上阅读有关过期的更多信息