c#asp.net中的Cookie [英] cookies in c# asp.net

查看:90
本文介绍了c#asp.net中的Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在c#asp.net应用程序中使用记住我".
条件是用户登录系统后,如果他们单击记住我"选项以在同一系统中下次使用,则密码必须存储在cookie中

请给我答案...非常紧急的

i want to know how to use ''remember me'' in c# asp.net application.
the criteria is once user logged in a system the password must be stored in cookies if they clicked the remember me option for next time usage in the same system

pls give me answer...its very urgent

推荐答案

尝试以下代码
try following code
if (chkRememberPassword.Checked == true) 
{ 
Response.Cookies["UName"].Value = txtUName.Text; 
Response.Cookies["PWD"].Value = txtPWD.Text; 
Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(2); 
Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(2); 
} 
else 
{ 
Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(-1); 
Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(-1); 
} 



将以下代码段粘贴到页面加载中



Paste the following code snippet in page load

if (!IsPostBack) 
{ 
if (Request.Cookies["UName"] != null) 
txtUName.Text= Request.Cookies["UName"].Value; 
if (Request.Cookies["PWD"] != null) 
txtPWD.Text.Attributes.Add("value", Request.Cookies["PWD"].Value); 
if (Request.Cookies["UName"] != null && Request.Cookies["PWD"] != null) 
chkRememberPassword.Checked = true; 
} 


记住我"是浏览器的一部分
''remember me''is a part of Browsers


看看:
http://forums.asp.net/t/1303629.aspx [ http://www.dotnetexpertsforum.com/remember-me- function-in-asp-net-with-c-t633.html [
have a look at :
http://forums.asp.net/t/1303629.aspx[^]
http://www.dotnetexpertsforum.com/remember-me-functionality-in-asp-net-with-c-t633.html[^]


这篇关于c#asp.net中的Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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