【问题标题】:Sql server session mode in asp.net web applicationsasp.net web应用程序中的sql server会话模式
【发布时间】:2013-01-07 05:32:44
【问题描述】:
我有两个项目解决方案。第一个是使用 asp.net (.aspx) Web 应用程序。第二个是 mvc (.cshtml) Web 应用程序。第一个应用程序具有到第二个应用程序的重定向链接。用户仅通过第一个应用程序登录。我想使用 sql server 会话模式将用户的用户登录详细信息和页面详细信息存储在 sqlserver 中。
任何建议都会有所帮助。谢谢
编辑
我尝试使用Link 中的sql server 会话模式。
会话值存储在 ASPState 数据库中。如何检查会话是否已过期以及过期会话中的值是否未使用。 ?
【问题讨论】:
标签:
c#
asp.net
asp.net-mvc
sql-server-2008
asp.net-mvc-4
【解决方案1】:
以下代码检查会话是否过期。
protected void Page_Init(object sender, EventArgs e)
{
if (Context.Session != null)
{
if (Session.IsNewSession)
{
HttpCookie newSessionIdCookie = Request.Cookies["ASP.NET_SessionId"];
if (newSessionIdCookie != null)
{
string newSessionIdCookieValue = newSessionIdCookie.Value;
if (newSessionIdCookieValue != string.Empty)
{
// This means Session was timed Out and New Session was started
// Do whatever you want
}
}
}
}
}