生产服务器上的表单 Cookie 过期太快
我在 web.config 中有以下设置
<authentication mode="Forms">
<forms loginUrl="~/Account/login"
slidingExpiration="true" timeout="2880" protection="All" />
</authentication>
,但 cookie 在不活动的五分钟内就会过期。对发生的事情有任何线索吗?
i have following settings in web.config
<authentication mode="Forms">
<forms loginUrl="~/Account/login"
slidingExpiration="true" timeout="2880" protection="All" />
</authentication>
but the cookie expires in less than five minutes of inactivity. Any clue on what is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在运行我的网站的网络主机上发现了这种行为。这一切都是在迁移到为 dotNET 4 准备的新服务器时开始的。web.config 完全被忽略,正如您提到的,五分钟似乎是断点。
你的问题让我开始四处寻找工作。我首先浏览 Stackoverflow 上的 forms-authentication 类别,这是您使用的标签之一。几分钟后,我发现了一个有点类似的问题: ASP.NET 表单身份验证一直显示登录页面。在接受的答案中,建议设置
cookieless="UseCookies
。我检查了自己的 web.config,发现
cookieless
被遗漏了,回到了默认配置。快速编辑和一些测试给出了积极的结果,但后来我像以前一样编辑了文件,现在我添加了一个元刷新。 > 也许是主机每十分钟重新加载一次页面。公司调整了一些参数。遗憾的是我没有为您提供解决方案:(不要在 Visual Studio 附带的 Web 服务器中运行您的服务,而是尝试在 IIS 中本地运行它,看看是否可以重现该问题。
(为了帮助用户回答这个问题,我想如果您提供一些有关生产服务器、组件版本等信息(例如您正在运行的 IIS 版本以及您运行站点时构建的框架版本),将会有所帮助。在测试中你使用IIS还是轻量级Web服务器在 Visual Studio 中?)
I recognize this behavior from a web host where I run one of my sites. It all started when moving to new servers, prepared for dotNET 4. The web.config is completely ignored and, as you mention, five minutes seems to be the break-point.
Your question made me start digging around, looking for a working. I started by browsing the forms-authentication category here on Stackoverflow, one of the tags you used. After a few minutes I found a somewhat similar question: ASP.NET forms authentication keeps displaying login page. In the accepted answer it was suggested to set
cookieless="UseCookies
.I checked my own web.config and found that
cookieless
was left out, falling back on the default configuration. A quick edit and some testing gave a positive result. It worked great. But then I edited the file back, as it was before and have now had a working session for ten ours. I added ameta-refresh
which reloaded the page every ten minutes. Perhaps the hosting company have tweaked some parameter. The sad thing is I have no solution for you :(Instead of running your service in the web server shipped with with Visual Studio, try to run it locally in IIS and see if you can reproduce the issue.
(To help users answer this questions I guess it would help if you provide some info about the production server, component versions and stuff. Like which version of IIS you're running and which framework version you build for. And, when you run your site in test do you use IIS or the light-weight web server in Visual Studio?)