Home > Net >  Setting cookies in.net expiration time do not work, regardless of the setting minvalue or not to set
Setting cookies in.net expiration time do not work, regardless of the setting minvalue or not to set

Time:09-19

Protected void Page_Load (object sender, EventArgs e)
{
HttpCookie a=Request. Cookies (" One ");
if(a!=null)
{
TextBox1. Text=Dr. Alues [r]. "one" the ToString ();
TextBox2. Text=Dr. Alues [r]. "two" the ToString ();
}
}

Protected void Button1_Click (object sender, EventArgs e)
{

If ((TextBox1. Text=="a") & amp; & (TextBox2. Text=="b"))
{
If (RadioButton1. Checked)
{
HttpCookie a=Request. Cookies (" One ");
If (a==null)
{
HttpCookie Mycookie=new HttpCookie (" One ");
[" one "Mycookie]=" a ";
"Two" Mycookie []="b";
The Response. Cookies. The Add (Mycookie);
Mycookie. Expires=DateTime. MinValue;
}
}

Response. Write (" & lt; script> Window. The open (' webform2.aspx ', '_parent') & lt;/script>" );
}
The else
{
Label3. Text="user name password input error!" ;
TextBox1. Text=null;
TextBox2. Text=null;
}

}

CodePudding user response:

The red part is the main code set the expiration time

CodePudding user response:

Do you know a DateTime MinValue is what? He is the default

You have set he expired, no problem?

Mycookie. Expires=DateTime. Now. AddDays (1);/////a day after the failure


CodePudding user response:

Thank you for your reply, I have solved this problem, a cookie name instead