我在应用程序代码session.cs
文件中使用了以下代码。它最初是在 httpmodule.cs 中加载的,每当浏览器中的每个页面都被点击时。我发现httpcontext.current.session
值是null
.
if (HttpContext.Current != null && HttpContext.Current.Session != null)
{
try
{
if (HttpContext.Current.Session.Keys.Count > 0)
{
}
else
{
HttpContext.Current.Response.Cookies["ecm"].Expires = DateTime.Now;
HttpContext.Current.Response.Cookies["ecmSecure"].Expires = DateTime.Now;
}
}
catch (Exception ex)
{
}
}
web.config 会话设置:
<sessionState mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="5" />