protected void Page_Load(object sender, EventArgs e)
{
HttpCookie a = Request.Cookies["One"];
if(a!=null)
{
TextBox1.Text = a.Values["one"].ToString();
TextBox2.Text = a.Values["two"].ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if ((TextBox1.Text == "a") && (TextBox2.Text == "b"))
{
if (RadioButton1.Checked)
{
HttpCookie a = Request.Cookies["One"];
if (a == null)
{
HttpCookie Mycookie = new HttpCookie("One");
Mycookie["one"] = "a";
Mycookie["two"] = "b";
Response.Cookies.Add(Mycookie);
Mycookie.Expires = DateTime.MinValue;
}
}
Response.Write("<script>window.open('WebForm2.aspx','_parent')</script>");
}
else
{
Label3.Text = "用戶名密碼輸入錯誤!";
TextBox1.Text = null;
TextBox2.Text = null;
}
}
uj5u.com熱心網友回復:
紅色部分是設定過期時間的主代碼uj5u.com熱心網友回復:
你知道DateTime.MinValue 是什么嗎?他就是 default你都把他設定過期了,沒毛病?
Mycookie.Expires = DateTime.Now.AddDays(1); ///// 一天后失效
uj5u.com熱心網友回復:
感謝您的回復,這個問題我已經解決了,改了個cookie的名字轉載請註明出處,本文鏈接:https://www.uj5u.com/net/62036.html
標籤:ASP.NET
上一篇:C#如果寫Windows程式?
下一篇:VS插入圖片問題請教
