ASP.NET cookie learning

xiaoxiao2021-03-06  117

Recently, the Cookie for ASP.NET has learned a cookie to the client to the client (for example, add a cookie) Request.Cookies client to the server's cookieprivate void button1_click (Object Sender, System.EventArgs E). ) {Httpcookie cookie = new httpcookie ("mytest"); // cookie.expires = DATETIME.NOW.ADDDAYS (1); cookie.values.add ("name", textbox1.text); // cookie value. You can access cookie.values.add ("pw", textbox2.text) by an indexer; cookie.value = "HelloWorld"; // cookie's single-value response.cookies.add (cookie); // Add cookie to Response write to the client Response.Write ( "Write Cookie to client Suc");} private void Button2_Click (object sender, System.EventArgs e) {HttpCookie Cookie = Request.Cookies [ "MyTest"]; // Cookie if made from the Request (Cookie == null) {response.write ("Client Haven't cookie of this web"); // Request is not cookie return;} textbox3.text = cookie.values ​​["name"]; // from cookie Take the value textBox4.text = cookie.values ​​["PW"]; textbox5.text = cookie.value;

}

转载请注明原文地址:https://www.9cbs.com/read-99335.html

New Post(0)