备案时填写 网站内容,免费ppt模板下载医学类,网页特效素材,网页制作的平台文章原址#xff1a;http://www.jb51.net/article/33588.htm 登录样子#xff0c;可以参考某一论坛的登录介面#xff1a; 记住这些信息#xff0c;可以使用Cookie来实现#xff0c;更多Cookie应用#xff0c;可参考 http://jb51.net/article/33590.htm http://jb51.net…文章原址http://www.jb51.net/article/33588.htm 登录样子可以参考某一论坛的登录介面 记住这些信息可以使用Cookie来实现更多Cookie应用可参考 http://jb51.net/article/33590.htm http://jb51.net/article/33591.htm 现在我们来模拟一个登录介面 复制代码 代码如下: table tr td stylewidth: 15%; text-align: right; User Name /td td asp:TextBox IDTextBoxUserName runatserver/asp:TextBox /td /tr tr td styletext-align: right; Password /td td asp:TextBox IDTextBoxPassword TextModePassword runatserver/asp:TextBox /td /tr tr td styletext-align: right; Remember me /td td asp:CheckBox IDCheckBoxRememberMe runatserver / /td /tr tr td styletext-align: right; /td td asp:Button IDButtonLogin runatserver TextLogin OnClickButtonLogin_Click / /td /tr /table 运行时的效果 我们要判断用户在点铵钮的Click事件时是否有选择Remember me这个CheckBox如果选中了要把这个登录的信息记录至Cookie还要把Cookie的过期时间设置7天之后过期。反之只把登录的信息记录入Cookie之中不设置Cookie的过期时间。可以参考下面的登录事件代码 复制代码 代码如下: protected void ButtonLogin_Click(object sender, EventArgs e) { Response.Cookies[Name].Expires DateTime.Now.AddDays(-1); Response.Cookies[Password].Expires DateTime.Now.AddDays(-1); if (CheckBoxRememberMe.Checked) { Response.Cookies[Name].Expires DateTime.Now.AddDays(7); Response.Cookies[Password].Expires DateTime.Now.AddDays(7); } Response.Cookies[Name].Value this.TextBoxUserName.Text.Trim(); Response.Cookies[Password].Value this.TextBoxPassword.Text.Trim (); } 接下来你还得在Page_load中去读取Cookie. 复制代码 代码如下: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.Cookies[Name] ! null Request.Cookies[Password] ! null) { this.TextBoxUserName.Text Request.Cookies[Name].Value; this.TextBoxPassword.Attributes[value] Request.Cookies[Password].Value; } } } 看看操作演示演示中有三种状态演示第一种是没有点选CheckBox这样的话关闭窗口下次再打开时没有记住登录的信息。第二是点选择了CheckBox这样下次再打开窗口还可以看到帐号与密码存储在相应的文本框中这都是Cookie没有过期。第三种再点一次登录没有点选remember me的CheckBox这样系统又移除了Cookie: 转载于:https://www.cnblogs.com/ydfq-home/p/5017356.html