For example, create a cookie called ASPCN, which is a small fish that is irrigated with water.
HttpCookie cookie = new httpcookie["ASPCN"];
Cookies. Value = "irrigation small fish";
Response.appendcookie (cookie);
It's also easy to remove the cookie value
HttpCookie cookie = request.cookies["ASPCN"];
Cookievalue = cookie. Value;
There is no problem in storing multiple messages in a cookie. For example, add more information under a cookie named ASPCN
HttpCookie cookie = new HttpCookie ("ASPCN");
Cookies. Values.add ("webmaster", "irrigation small fish");
Cookies. Values.add ("writer", "Beige");
Cookies. Values.add ("LinkColor", "Blue");
Response.appendcookie (cookie);
It's just as easy to take out information
HttpCookie cookie = request.cookies["ASPCN"];
value1 = cookies. values["Webmaster"];
value2 = cookies. values["Writer"];
HttpCookie cookie = Request.cookies[strkey];
if (null = = cookie)
{
Cookie does not exist
}
Let's see if there's a write client
Cookie=new HttpCookie ("www.xx.org");
Cookies. Values.add ("Usertype", DdlLoginType.SelectedItem.Value);
Cookies. Values.add ("UserName", TbUserName.Text.Trim ());
Cookies. Values.add ("Password", TbPassword.Text.Trim ());
Cookies. Values.add ("Access", i.ToString ());
Response.appendcookie (cookie);
Check if the cookie has been written to the browser
Cookie = request.cookies["www.xx.org"];
if (cookie==null| | Cookies. ToString () = = "")
{
Store with session
Loginuser loginuser = new Loginuser ();
Loginuser.username = TbUserName.Text.Trim ();
Loginuser.password = TbPassword.Text.Trim ();
Loginuser.usertype = DdlLoginType.SelectedItem.Value;
Loginuser.access = i;
session["www.xx.org"] = Loginuser;
}
My previous code, no problem with
The >>> page was just refreshed once
If you debug, does the code get executed on all? By the "is" doing any validation?
>>> then the delete
>>>response.cookies.remove ("MyCookie");
>>>response.redirect ("....")//steering
>>> then the delete
HttpCookie cookie = request.cookies["MyInfo"];
if (cookie = null)
{
Cookies. Expires = System.DateTime.Now.AddDays (-1);
}
RESPONSE.COOKIES.ADD (cookie);
response.cookies["Logincode"]. Expires =datetime.now.addhours (1);
This is valid for 1 hours, and the same method can be analogous to a few minutes, a few seconds, and so on.
How to use cookies in. Net