我在mvc 4
开发了一个使用代码第一实体框架的网站。我在登录我的网站时使用了HttpContext.GetOwinContext()。SignIn。
HttpContext.GetOwinContext().SignIn(user, model.RememberMe);
HttpContext.SetSession(WebConstants.SessionUser, user);
当我登录时,它会存储user
个会话。我有一个Index
视图。在该视图上,我创建了六到七个菜单标签。第一次打开时,它会加载第一个菜单选项卡。加载时,它从表中获取一些数据并在视图上显示。所以每个标签都有一些数据。我创建了一个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);
}
.....
......
......
我正在使用此方法从表中获取数据并在选项卡视图中显示它。在这里,我的问题是,如果我在这些选项卡之间不断导航会话即将到期。我认为如果当前进程正在执行并且我单击其他选项卡时会发生此问题,因此执行过程中断。谁能告诉我如何解决这个问题?
答案 0 :(得分:0)
请检查启动配置中的过期设置,例如:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
ExpireTimeSpan = TimeSpan.FromHours(4.0),
SlidingExpiration = true
});
您可以阅读有关过期的更多信息 http://www.jamessturtevant.com/posts/ASPNET-Identity-Cookie-Authentication-Timeouts/