我在主网站的子域名上托管了asp.net MVC 3.0
网站。 Asp.net
版本设置为.Net 4.0 integrated pipeLine
。
表单身份验证设置如下:
<authentication mode="Forms">
<forms
cookieless="UseCookies"
defaultUrl="~/home"
enableCrossAppRedirects="false"
path="/"
requireSSL="false"
loginUrl="~/account/login"
protection="All"
timeout="120"
slidingExpiration="true"
name=".SubDomainAuthCookie"></forms>
</authentication>
但记录我 out 每次只需几分钟!由于编码错误或繁重的任务导致应用程序池,主机管理员表示可能重置,但这是一个简单的mvc 网站 EF ORM 。我无法弄清楚该做什么!我应该寻找什么可能导致这种情况?
更新:
检查Application_Start
后,我发现这是问题,我记录了Application_Start()
,结果是 我正在退出,日志已添加。
12/6/2012 12:14:03 PM ==> Application started
12/6/2012 12:16:35 PM ==> Application started
12/6/2012 12:22:59 PM ==> Application started
奇怪,但真实。逻辑上没有任何复杂或沉重的东西! EF可能是问题,是否会消耗大量内存/ CPU导致应用程序池重置?
答案 0 :(得分:3)
FormsAuthentication.SetAuthCookie
之前使用FormsAuthentication.RedirectFromLoginPage
?如果没有,可能没有正确设置身份验证cookie。尝试记录global.asax.cs的Application_End,以了解您的应用是否回收过多。
protected void Application_End(object sender,EventArgs e) { / 记录Application_End / }
正如@ZippyV在下面的一个答案中提到的,其背后的原因是IIS默认设置为自动生成一对密钥用于解密并验证每个AppPool上的授权cookie内容(以及其他内容)回收称为MachineKey。 Also mentioned in this question
更改此密钥后,所有浏览器上存储的授权cookie内容将不再可读,授权将丢失。
最简单的补救措施是在web.config中使用静态MachineKey
还尝试将Cookie设置为父域。 more info here
答案 1 :(得分:1)
当我的托管服务提供商过于频繁地回收我的网站流程时,我也遇到了这个问题。由于某种原因,验证cookie变得无效,因为加密/解密密钥会发生变化。因此,您的网站无法再读取身份验证Cookie。
您可以通过在web.config中指定密钥来解决此问题,以便托管服务提供商无法更改这些密钥:
<system.web>
答案 2 :(得分:0)
您还需要设置登录时生成的Cookie的过期时间。 在形式上,你必须使用它。
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, //Here Userinformation, DateTime.Now, DateTime.Now.AddDays(1), false, string.Empty);
这里我已经将Cookie的过期时间设置为DateTime.Now.AddDays(1)(登录日期+ 1天),因此它将会记录太长时间。 因此,创建的故障单将在您登录后的第二天到期。
在Web.Config中
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
现在很长一段时间你都可以登录。
希望它有所帮助!!!
检查这些链接,以便更深入地了解创建登录和到期时间。
http://www.hanselman.com/blog/WeirdTimeoutsWithCustomASPNETFormsAuthentication.aspx
和
答案 3 :(得分:0)
您是否在SessionState中检查了价值?它的默认值是20分钟。您需要将其更新为与表单身份验证票证相同或更高。
请在配置文件中添加/更新以下标记。
**<sessionState timeout="120" />**