Jquery cookie and asp.net implement logging in and remembering the username and password

Source: Internet
Author: User
Tags httpcontext

Jquery implements cookie login to remember the username and password problem. You only need to write the corresponding js method on the page without any processing at the background, and you will be able to remember the username and password at the next login.

First, we will introduce how jquery reads cookies.

Example $. cookie (the _ cookie, the _ value ');
Set the cookie value
Example $. cookie (the _ cookie, the _ value, {expires: 7, path: '/', domain: 'jquery. com ', secure: true });
Create a cookie, including the domain name of the validity period.
Example $. cookie (the _ cookie, the _ value ');
Create cookie
Example $. cookie (the _ cookie, null );
Delete a cookie

View a dz cookie traversal method

Processing of split arrays

Function getcookie (name ){
Var cookie_start = document. cookie. indexof (name );
Var cookie_end = document. cookie. indexof (";", cookie_start );
Return cookie_start =-1? '': Unescape (document. cookie. substring (cookie_start + name. length + 1, (cookie_end> cookie_start? Cookie_end: document. cookie. length )));
}
Function setcookie (cookiename, cookievalue, seconds, path, domain, secure ){
Var expires = new date ();
Expires. settime (expires. gettime () + seconds );
Document. cookie = escape (cookiename) + '=' + escape (cookievalue)
+ (Expires? '; Expires =' + expires. togmtstring ():'')
+ (Path? '; Path =' + path :'/')
+ (Domain? '; Domain =' + domain :'')
+ (Secure? '; Secure ':'');
}


Okay, there's a lot to talk about. Now let's get in.

Public static void showcookies ()
        {
Int16 I;
Httpcookiecollection cookies = system. web. httpcontext. current. request. cookies;
For (I = 0; I <cookies. count; I ++)
            {
Httpcookie cookie = cookies. get (I );
System. web. httpcontext. current. response. write ("cookie name:" + cookie. name + "<br/> ");
System. web. httpcontext. current. response. write ("value =:" + cookie. value + "<br/> ");
System. web. httpcontext. current. response. write ("expires duration:" + cookie. expires. tostring () + "<br/> ");
System. web. httpcontext. current. response. write ("// System. web. httpcontext. current. response. write ("domain:" + cookie. domain + "<br/> ");
// System. web. httpcontext. current. response. write ("path:" + cookie. path + "<br/> ");
// System. web. httpcontext. current. response. write ("secure Confidential:" + cookie. secure + "<br/> ");
            }
System. web. httpcontext. current. response. write ("total" + cookies. count + "cookies <br/> ");
        }
Public static void deleteallcookies ()
        {
Int16 I;
Httpcookiecollection cookies = system. web. httpcontext. current. request. cookies;
For (I = 0; I <cookies. count; I ++)
            {
Httpcookie cookie = cookies. get (I );
Cookie. value = "";
Cookie. expires = datetime. now. adddays (-365 );
System. web. httpcontext. current. response. cookies. set (cookie );

            }
System. web. httpcontext. current. response. write ("total" + cookies. count + "cookies deleted <br/> ");

/* Cookies. clear ();*/
        }
Public static void clearallcookies ()
        {
Int16 I;
Httpcookiecollection cookies = system. web. httpcontext. current. request. cookies;
For (I = 0; I <cookies. count; I ++)
            {
Httpcookie cookie = cookies. get (I );
Cookie. value = "";
System. web. httpcontext. current. response. cookies. set (cookie );
            }
System. web. httpcontext. current. response. write ("total" + cookies. count + "cookies cleared <br/> ");
        }


 

Jquery cookie plug-in download address

Http://plugins.jquery.com/project/cookie

Related Article

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.