【发布时间】:2010-07-28 01:14:11
【问题描述】:
使用 Asp.Net MVC 1,我有我的“登录”控件/页面...我选中“记住我”复选框并点击提交.. 在我的控制器中我有:
FormsAuth.SignIn(userName, password, rememberMe)
这个方法创建了持久化的cookie .ASPXAUTH,此时一切都很好。我在其他控制器中设置了一个断点,我注意到一旦我登录到网站......对于下一个“回发”或页面刷新... cookie .ASPXAUTH 已从 cookie 集合中消失...所以.. 当我回到站点时,即使我选择了“记住我”选项.. 它会再次使用登录表单询问我的凭据...
知道为什么会这样吗?
更新:
我认为这不是 MVC 的问题。我用 WebForms 创建了一个新应用程序,该页面包含 1 个文本框、1 个生成 cookie 的按钮……以及将 cookie 写入标签的其他按钮……http://screencast.com/t/MjQ1MTVmYWU
这是我的代码:
protected void Button1_Click(object sender, EventArgs e)
{
HttpCookie cookie = new HttpCookie("test");
cookie.Value = TextBox1.Text;
cookie.Expires = DateTime.Now.AddMinutes(1);
Response.Cookies.Add(cookie);
}//with a breakpoint here, I "watch" the Response.Cookies collection and I can see my "test" item there.
protected void Button2_Click(object sender, EventArgs e)
{//with a breakpoint here. the Response.Cookies collection is empty.
Label1.Text = Response.Cookies["test"].Value ?? "null";
}
我得到了相同的结果.. cookie 已正确添加到 Response.Cookies 集合中,但在第二次回发中,该集合再次为空..
结果..标签的值为“null”。
也许是一些配置?我以前从未使用过 cookie。
【问题讨论】:
-
我也尝试过添加自己的 cookie:Response.Cookies.Add(mycookie);并且添加成功,但是对于下一次“回发”,cookie 集合为空
-
所有浏览器都会出现这种情况吗?
-
什么浏览器?你不是在隐身模式吗?
-
我在 IE8 和 Mozilla Firefox 3.6.8 都试过
-
我注意到了别的东西..我正在使用 Mozilla 的工具提琴手.. 而 Visual Studio 2008 调试器告诉我 Cookies 集合是空的...提琴手捕获的请求/响应向我展示了 cookie……但我无法在 IE 和 localhost 中使用提琴手……
标签: asp.net-mvc authentication cookies webforms login