Read and set a function of cookie

xiaoxiao2021-03-06  32

Premise preparation conditions:

1. You have to have 2 TextBox controls, one to lose your password, one is used to lose username, but I don't think that these are required.

2. You have a RadiobuttonList control to set the cookie's survival time. About internal depends is: year y, month m, week W, day D, browser process P.

3. Ok, now you can embed the following code in the page PageLoad:

Note: It is said that in ASP.NET, there is no built-in setting FOCUS, please use the JavaScript control name. Focus implementation

Public void check (system.web.ui.webcontrols.textbox tb, system.web.ui.webcontrols.radiobuttonlist video)

{

HTTPCOOKIE HC = Request.Cookies ["TestCookie"];

IF (hc! = null)

Tb.Text = Hc.Value;

Else

{

HC = New httpcookie ("TestCookie", TB.Text);

DateTime DT = datetime.now;

Timespan TS = New Timespan (365, 0, 0);

IF (choise.selecteditem.value == "y")

Ts = new timeespan (365, 0, 0);

Else if (choise.selecteditem.value == "m")

TS = New TimeSpan (30, 0, 0);

Else if (choise.selecteditem.value == "w")

Ts = new timeespan (7, 0, 0);

Else if (choise.selecteditedItem.value == "d")

Ts = new timeespan (1, 0, 0);

Hc.expires = dt.add (ts);

Response.cookies.Add (HC);

}

}

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

New Post(0)