Saving and automatic landing of accounts in asp.net environment

Source: Internet
Author: User

General site landing will automatically save a few days of check box, below us. NET environment to realize the preservation of the account and automatic landing.

We need to use the HttpCookie class here.

<summary>
    ///processing cookies
    ///</summary>
    ///<param name= "name" ></param>
    <param name= ' pass ' ></param>
    ///<returns></returns> public
    HttpCookie Httpsavecookie (string name, String pass)
    {
        HttpCookie HTC = new HttpCookie ("Userlogin");
        Htc. Values.add ("username", name);
        Htc. Values.add ("Userpass", pass);
        Htc. Expires = DateTime.Now.AddDays ();
        return HTC;
    }

When you need to save your account, you should add it before the login code:

Whether to save cookies

if (checkbox2.checked)

Response.Cookies.Add (Httpsavecookie (strname, Strpass));

Where strname and Strpass is the user's account name and password, it is important to note that, for the sake of security, the saved password must be ciphertext, and automatically logon when the time will not be encrypted to judge.

To achieve automatic login, when loading the login page to determine whether there is a cookie, some words directly to get the data to judge, success is logged in.

Implementation code:

if (request.cookies["userlogin"]!= null)
{
    HttpCookie HTC = request.cookies["Userlogin"];
    String getname = HTC. values["username"]. ToString ();
    String getpass = HTC. values["Userpass"]. ToString ();
    BOOL data = Sprocedure.userlogin (GetName, getpass);
    //......    
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/aspx/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.