简体   繁体   English

ASP.Net中的“记住我”

[英]“Remember Me” in ASP.Net

I am new to C# Programming. 我是C#编程的新手。

I had drag a login control into my website. 我已经将登录控件拖到我的网站中。 But the "Remember me" seem not to be working if i didn't add any codes in. 但是,如果我未添加任何代码,则“记住我”似乎无法正常工作。

Anyone can teach me how to implement the "remember me" in c#? 任何人都可以教我如何在c#中实现“记住我”?

I want it to be when the user revisit the website, he/she type onto the username textbox, the password will be retrieved from the database and display on the password textbox and at the same time the rememberme checked box will be check. 我希望它是当用户重新访问该网站时,他/她在用户名文本框上键入,密码将从数据库中检索并显示在密码文本框上,同时将选中“记住我”复选框。

I had been researching this for the code for was for days, but was not fruitful. 我已经花了几天的时间研究代码,但效果并不理想。

Anyone can give me a tutorial on this? 任何人都可以给我教程吗?

Desperately wanting to know how it works. 拼命想知道它是如何工作的。

Hope to get reply soon. 希望能尽快得到答复。

Thank. 谢谢。

Anyone can teach me how to implement the "remember me" in c#? 任何人都可以教我如何在c#中实现“记住我”?

From MSDN : MSDN

  1. If you want the control to display a "Remember me next time" check box, set the DisplayRememberMe property to true . 如果您希望控件显示“下次记住我”复选框,请将DisplayRememberMe属性设置为true If a user selects the "Remember me next time check box" when he or she logs in, the authentication token will be stored in a persistent cookie in the browser. 如果用户登录时选中“下次记住我”复选框,则身份验证令牌将存储在浏览器中的持久cookie中。

  2. If you want the "Remember me next time" check box to be selected by default, set the RememberMeSet property to true . 如果要默认选中“下次记住我”复选框,请将RememberMeSet属性设置为true

  3. If you want the authentication token to be stored in a persistent cookie without giving the user the option to clear the "Remember me next time" check box, set the RememberMeSet property to true and set the DisplayRememberMe property to false . 如果您希望将身份验证令牌存储在持久性cookie中,而又不给用户提供清除“下次记住我”复选框的选项,则将RememberMeSet属性设置为true ,并将DisplayRememberMe属性设置为false This is not recommended for sites that can be accessed from public computers that serve multiple users, as a user's persistent authentication token could be used by an unwanted user. 对于可以从为多个用户提供服务的公用计算机上访问的网站,建议不要使用此方法,因为不需要的用户可以使用用户的持久身份验证令牌。

I want it to be when the user revisit the website, he/she type onto the username textbox, the password will be retrieved from the database and display on the password textbox and at the same time the rememberme checked box will be check. 我希望它是当用户重新访问该网站时,他/她在用户名文本框上键入,密码将从数据库中检索并显示在密码文本框上,同时将选中“记住我”复选框。

That's not how the "Remember Me" checkbox works. 这不是“记住我”复选框的工作方式。 All the checkbox does is store an authentication ticket in a cookie in the browser. 复选框所做的只是将身份验证票证存储在浏览器的Cookie中。 When the user revisits the site, there is no prompt for login as the authentication ticket already exists, so the user is automatically logged in. 当用户重新访问该站点时,由于身份验证票证已存在,因此没有登录提示,因此该用户将自动登录。

It's conceivable that you could modify the login ASCX with some JavaScript to do exactly what you want, but in good conscience I cannot recommend you do that as it would render your site incredibly insecure. 可以想象,您可以使用一些JavaScript修改登录ASCX来实现您想要的功能,但是出于良心,我不建议您这样做,因为这会使您的网站变得非常不安全。

The way you think the "remember me" check box works is incorrect. 您认为“记住我”复选框的工作方式不正确。 When a user selects Remember Me, if they successfully login, their user name and password are stored in a session cookie until the cookie expires. 当用户选择“记住我”时,如果他们成功登录,则其用户名和密码将存储在会话cookie中,直到cookie过期。 Nothing is retrieved from the database at this time - that is very insecure! 目前没有从数据库中检索到任何内容-这是非常不安全的!

EDIT ** May I suggest watching a video on the built-in ASP.Net Login server controls. 编辑**我可以建议在内置的ASP.Net登录服务器控件上观看视频 I think that you should use these while you are getting a handle on ASP.Net & C# programming. 我认为在了解ASP.Net和C#编程时,应该使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM