如何在asp.net中将持久性cookie设置为true. [英] How to set the persistant cookie to true in asp.net..
本文介绍了如何在asp.net中将持久性cookie设置为true.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人对我如何将持久性设置为true和
有任何想法吗?
保留了cookie,使我不必登录下一个
Does anyone have any thoughts on how I can set persistence to true and
have the cookie retained to enable me not to have to login the next
time I visit the site?
推荐答案
您未设置持久性"属性,而是设置了到期日期/时间:
0)创建cookie
1)添加用户的凭据
2)设置到期时间
3)将Cookie写入客户端计算机
You don''t set a "persitence" property, you set an expiration date/time:
0) Create the cookie
1) Add the user''s credentials
2) Set the expire time
3) Write the cookie to the client machine
HttpCookie myCookie = new HttpCookie("myCookie");
myCookie.Values.Add("userid", objUser.id.ToString());
myCookie.Expires = DateTime.Now.AddDays(5);
Response.Cookies.Add(myCookie);
That''s all there is to it.
嘿,我认为代码没有任何问题,请检查浏览器中的cookie设置,不同的浏览器具有不同的启用界面/禁用cookie.
尝试一次..
Hey i think there is no any problem with the code, please check for the setting for cookie in browser, different browser have different interface for enabling/disabling cookie.
try once..
这篇关于如何在asp.net中将持久性cookie设置为true.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文