这里有一段代码从登录页的表单返回永久性cookie,并限制它的时效为7天:
string url = FormsAuthentication.GetRedirectUrl ("Elmo", true);
FormsAuthentication.SetAuthCookie ("Elmo", true);
HttpCookie cookie = Response.Cookies[FormsAuthentication.FormsCookieName];
cookie.Expires = DateTime.Now + new TimeSpan (7, 0, 0, 0);
Response.Redirect (url);
可以通过改变TiemSpan的值来改变cookie的时效。
string url = FormsAuthentication.GetRedirectUrl ("Elmo", true);
FormsAuthentication.SetAuthCookie ("Elmo", true);
HttpCookie cookie = Response.Cookies[FormsAuthentication.FormsCookieName];
cookie.Expires = DateTime.Now + new TimeSpan (7, 0, 0, 0);
Response.Redirect (url);
可以通过改变TiemSpan的值来改变cookie的时效。
解决方案 »
- 怎么样防止网站被注入恶意JS代码。
- 请教正则表达试
- 统计链接来源!并且把从何处链也给找出来
- 怎么将this.TextBox4.Text.ToString().Trim(); 转换成 Nvarchar格式 也就是unicode编码?
- 求一个下载vs2010中文版的下载地址
- vs2005中的奇怪问题!
- xmlDoc.CreateNode和CreateElement的区别?
- 急求毕业论文题目
- asp.net程序在调试时aspnetwp_exe进程会占用cpu100%,导致程序没有响应,会不会是有病毒了,因为程序代码没有变化和以前是一样的,
- DataGrid 中自动生成列,怎样控制一个cell中的内容不换行?
- 刚学asp.net,大家觉得用什么编辑器好一点?
- 我重装了IIS,应该怎样启动ASP.NET?
HttpCookie tmpCooki = new HttpCookie("NYJ");
tmpCooki.Value="HI";tmpCooki.Expires=DateTime.Now.AddDays(1);
Response.Cookies.Add(tmpCooki);HttpCookie t = new HttpCookie("N");
t.Values.Add("UserName","Knight");
t.Values.Add("Age","23");t.Expires=DateTime.Now.AddHours(1);
Response.Cookies.Add(t);读取
Label1.Text="";
Label1.Text+=Request.Cookies["NYJ"].Value+"<br/>";
Label1.Text+=Request.Cookies["N"]["UserName"]+"<br/>";
Label1.Text+=Request.Cookies["N"]["Age"]+"<br/>";
http://expert.csdn.net/Expert/topic/1082/1082426.xml?temp=.6507837
Response.Cookies("my")("UserPassword") = UserPassword
Response.Cookies("my").Expires = DateTime.Now.AddDays(30)
'增加COOKIES的时间