为什么不工作我的ASP.NET MVC持续权威性饼干吗?
我使用ASP.NET MVC 3,与窗体身份验证(基于改进香草帐户code你拿到文件 - >新建)。
I'm using ASP.NET MVC 3, with forms authentication (based on modified vanilla account code you get with file->new).
当你登录,我设置一个AUTH的cookie
When you login, I am setting an auth cookie with
FormsAuthentication.SetAuthCookie(userName, true);
因此,这应该设置一个永久性的Cookie。但是,如果我关闭浏览器,然后重新打开,当我浏览到该网站,我不得不重新登录!我可以看到使用该Cookie(.ASPXAUTH)正在建立,而不是当我关闭浏览器被删除Chrome浏览器开发工具,因此发生了什么?
So this should set a persistent cookie. But if I close the browser and re-open, when I browse to the site I am forced to log in again! I can see using chrome dev tools that the cookie (.ASPXAUTH) is being created and not being deleted when I close the browser, so what's happening?
我的web.config:
My web.config:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogIn" timeout="10000"/>
</authentication>
我在本地测试这一点,在IIS下如果让任何区别。
I'm testing this locally, under IIS if that makes any difference.
从评论从解决@alexl:
Solved from comment from @alexl:
您可以检查这个答案:Making用户登录持续性与ASP.NET的成员
you can check this answer: Making user login persistant with ASP .Net Membership
好吧,这似乎链接排序对我来说 - 与SetAuthCookie坚持和调整我的配置明确设置cookie的名称(在web.confg),现在一切工作正常。奇怪的! -
Ok, this link seemed to sort it for me - sticking with SetAuthCookie and tweaking my config to explicitly set the cookie name (in the web.confg), and all is working now. Weird! –