Front desk JS settings cookies Background Read the cookies just set

Source: Internet
Author: User
Tags allkeys setcookie

Today, while collating the code, I found that half of the previous functions were not implemented. Perfect today, and selfless to share the code to everyone.

Front Code:

1 <!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">2 3 <HTMLxmlns= "http://www.w3.org/1999/xhtml" >4 <Headrunat= "Server">5     <title>HTML5 Learning</title>6 </Head>7 <Body>8     <formID= "Form1"runat= "Server">9     <Div>Ten     One     <inputID= "Text1"type= "text"onchange= "Setcookie (' gid_434 ', ' 434 ')"/> A     </Div> -     </form> - </Body> the </HTML> - <Scripttype= "Text/javascript"> -     functionSetcookie (name, value) { -         var Days=  -; +         varExp= NewDate ();  - Exp.settime (Exp.gettime ()+ Days*  - *  - *  - *  +); + Document.cookie=name+ "=" +Escape (value)+ "; expires=" +exp.togmtstring (); A     } at </Script>

Background code:

usingSystem;usingSystem.Linq;usingsystem.web;  Public Partial classGetCookies:System.Web.UI.Page {protected voidPage_Load (Objectsender, EventArgs e) {            stringErr_msg =string.            Empty; if(Request.Cookies.AllKeys.Count () >0&& Request.Cookies.AllKeys.Contains ("gid_434"))            {                if(request.cookies["gid_434"]. Value = =NULL) {err_msg="cookies:gid_434 temporarily no data"; Response.Write (string. Format ("<script>alert (' {0} ') </script>", err_msg)); }                Else{err_msg= request.cookies["gid_434"].                    Value.tostring (); Response.Write (string. Format ("<script>alert (' {0} ') </script>", err_msg)); }            }            Else{err_msg="cookies are empty"; Response.Write (string. Format ("<script>alert (' {0} ') </script>", err_msg)); }        }    }

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.