为什么Cookies没有注销?
Default.aspx页面必须经过登陆之后才能访问,选中 "保存Cookies "复选框,点击登陆,经过一系列操作后点击注销,为什么注销后还能直接访问Default.aspx?
登陆时的代码:
if (this.txtUserName.Text != " " && this.txtPwd.Text != " ")
{
if (this.chkHistory.Checked)
{
DateTime dtime = DateTime.Now;
TimeSpan ts = new TimeSpan(30,0,0,0,0);
dtime = dtime.Add(ts);
Response.Cookies[ "ERPSYSTEM "][ "username "] = txtUserName.Text;
Response.Cookies[ "ERPSYSTEM "][ "Password "] = txtPwd.Text;
Response.Cookies[ "ERPSYSTEM "].Expires = dtime;
}
Response.Redirect( "LoginFailed.aspx ");
}
注销是的代码:
Response.Cookies[ "ERPSYSTEM "][ "username "] = " ";
Response.Cookies[ "ERPSYSTEM "][ "Password "] = " ";
Response.Cookies[ "ERPSYSTEM "].Expires = DateTime.MinValue;
FormsAuthentication.SignOut();
Default.aspx的代码:
if (!Page.IsPostBack)
{
if (Request.Cookies[ "ERPSYSTEM "][ "username "] == null && Request.Cookies[ "ERPSYSTEM "][ "username "].ToString() == " ")
{
Response.Write( "there is no cookie ");
}
else
{
Response.Write( "there is cookie ");
}
}
[解决办法]
超时,就过期了
[解决办法]
没看到这句:Response.Cookies.Add(cookie);
过期日期可设的更久远一些
[解决办法]
cookies是可以保存在浏览器中的,你可能是其他的网页没有关掉,你的cookies还保存在浏览器中,看看是不是这样?你把浏览器关掉。