我需要帮助弄清楚为什么我的身份验证票证在我的托管网站上大约一个小时后就过期了。 但是,如果我在本地运行该站点,身份验证票证将在正确的时间内保持活动状态。
这是我的本地主机 web.config:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="20160" slidingExpiration="true" path="/" />
</authentication>
这是我的托管 web.config:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="20160" slidingExpiration="true" domain=".mywebsite.com" path="/" />
</authentication>
我知道正在创建身份验证票证,因为:
- 我可以在浏览器 cookie 中看到它
- 即使在关闭浏览器并重新打开后
- 我仍保持登录状态即使在网站回收之后(更改并保存 web.config 以回收它),
当我在浏览器中检查 cookie 过期日期时,已经是 2 周后了。 然而,大约一个小时后,我的身份验证总是过期。
我该如何找出托管网站的身份验证如此早过期的原因?
我不知道如何解决这个问题,因为我的托管网站是唯一有问题的网站。
更新 1:等待 1 小时后,我检查浏览器,发现 cookie 仍然存在。 事实上,它的有效期被设定为两周后。 但是,如果我重新加载页面或尝试转到任何需要身份验证的页面,我将被带到登录页面。
I need help figuring out why my authentication ticket is expiring after about an hour on my hosted website. But if I run the site locally the authentication ticket stays alive for the correct amount of time.
This is my localhost web.config:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="20160" slidingExpiration="true" path="/" />
</authentication>
and this is my hosted web.config:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="20160" slidingExpiration="true" domain=".mywebsite.com" path="/" />
</authentication>
I know the authentication ticket is being created because:
- I can see it in the browser cookies
- I stay logged in even after closing the browser and reopening
- I stay logged in even after website recycles (changing and saving web.config to recycle it)
When I check the cookie expiration date in the browser it's 2 weeks later. However, after about an hour my authentication always expires.
What can I do to figure out why the hosted website's authentication is expiring so early?
I don't know how to go about resolving this problem since it's my hosted website that is the only one having problems.
Update 1: After waiting 1 hour, I check my browser and I see the cookie still exists. In fact it's expiration date is set for 2 weeks later. But if I reload the page or try going to any pages that requires authentication I am taken to the login page.
发布评论
评论(3)
我在 system.net 中添加了一个 machinekey 条目。 像这样的事情:
现在它让用户保持登录状态。但是,现在我似乎遇到了性能问题。 页面加载时间过去大约需要 500 毫秒,现在则需要大约两倍的时间。
I added a machinekey entry in system.net. Something like this:
and now it keeps the user logged in. However, now it seems like I am having performance issues. The page used to take roughly 500ms to load now takes about double that time.
我会尝试几种方法来解决此问题:
I would try several things in troubleshooting this:
您是否询问过您的托管提供商 machine.config 是否将此设置为不同的值? machine.config 上的设置将覆盖 web.config。
Have you asked your hosting provider if the machine.config has this set to a diferent value? Settings on machine.config will override the web.config.