在ASP.NET的会话状态cookie的有效期更改 [英] Changing expiry on ASP.NET's Session State cookie

查看:637
本文介绍了在ASP.NET的会话状态cookie的有效期更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET会话状态跟踪记录在我的网站上的用户。



不过,有一个问题我运行到是,通过默认的ASP.NET会话cookie设置在浏览器关闭过期。





我试过设置自己的cookie ASP.NET_SessionId和修改使用类似于下面的代码的东西cookie的有效期:



<$ p 。$ p> Response.Cookies [ASP.NET_SessionId] =到期DateTime.Now.AddMonths(1);



这些方法都没有工作,他们都设置有相同名称的第二个cookie。



有没有会话cookie的有效期的一种方式?


解决方案

我会建议用于跟踪登录的用户FormsAuthentication。您可以使用持久FormsAuthenticationCookie达到你想要什么



或者,如果你真的想使用会话状态,尝试的这种技术


I'm using ASP.NET Session State to keep track of logged in users on my site.

However, one problem I'm running into is that by default ASP.NET session cookies are set to expire when the browser closes.

I've tried setting my own ASP.NET_SessionId cookie and modifying the cookie's expiry using something similar to the following code:

Response.Cookies["ASP.NET_SessionId"].Expires = DateTime.Now.AddMonths(1);

None of these approaches work, they all set a second cookie with the same name.

Is there a way of changing the session cookie's expiry?

解决方案

I would suggest you use FormsAuthentication to track logged in users. You can use a persistent FormsAuthenticationCookie to achieve what you want.

Or if you really want to use Session State, try this technique.

这篇关于在ASP.NET的会话状态cookie的有效期更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆