为什么我有2个ASPXAUTH cookie而不是1?

时间:2013-12-10 12:27:23

标签: c# asp.net visual-studio-2010 authentication .aspxauth

我正在创建一个asp.net应用程序,它现在已经工作了,但问题是当我使用“Live HTTP Headers”时,我发现我的网站有2个ASPXAUTH cookie,而正在使用的是底层的。

在这里我给我发现的屏幕截图:

enter image description here

顺便说一下,这是我登录页面中的一些代码:

  string email = tbEmail.Text;
                string pass = tbPass.Text;
                bool remember = cbRemember.Checked;

                var res = (from user in ctx.users
                          where user.password == ctx.ConvertPassword(pass) 
                                                 && user.email == email
                          select user).FirstOrDefault();  // Remark : 0 = active, 1 = Inactive, 2 = Suspend, 3 = Unconfirmed

                if (res != null && res.email.ToLower() == email.ToLower())
                {
                    if (res.userstatus == 0 || res.userstatus == 3)
                    {
                        FormsAuthentication.SetAuthCookie(email, remember);
                        FormsAuthentication.RedirectFromLoginPage(email, remember);
                        var arr =  Request.Cookies.AllKeys;
                    }
                    else if (res.userstatus == (int)UserStatus.Inactive)
                    {
                        lblMessage.Text = "You have deleted your account, if you wish to restore it, please click ";
                        btRecover.Visible = true;
                    }
                    else if (res.userstatus == (int)UserStatus.Suspended)
                    {
                        lblMessage.Text = "Your account has been suspended, for more information, please contact our support";
                    }
                    else
                    {
                        lblMessage.Text = "Invalid username or password";
                    }
                }
                else
                {
                    lblMessage.Text = "Invalid username or password";
                }

我做错了什么?

1 个答案:

答案 0 :(得分:0)

FormsAuthentication.SetAuthCookie(email, remember);

设置cookie。但也是

FormsAuthentication.RedirectFromLoginPage(email, remember);

这是一个更高级别的外观 - 不仅设置cookie,还从登录页面重定向到redirecturi指向页面。