Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 为什么赢了';我的表单身份验证不能保持登录状态吗?_Asp.net_Asp.net Mvc_Forms Authentication - Fatal编程技术网

Asp.net 为什么赢了';我的表单身份验证不能保持登录状态吗?

Asp.net 为什么赢了';我的表单身份验证不能保持登录状态吗?,asp.net,asp.net-mvc,forms-authentication,Asp.net,Asp.net Mvc,Forms Authentication,我在mvc项目中使用表单身份验证,无论我做什么。您只能登录一天,然后需要重新登录 在我的web.config中,我将超时设置为以分钟为单位的一周 <authentication mode="Forms"> <forms loginUrl="~/Account/Login" timeout="10080" defaultUrl="/kpi" slidingExpiration="true" /> </authentication> 您需要使用FormsAu

我在mvc项目中使用表单身份验证,无论我做什么。您只能登录一天,然后需要重新登录

在我的web.config中,我将超时设置为以分钟为单位的一周

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="10080" defaultUrl="/kpi" slidingExpiration="true" />
</authentication>

您需要使用
FormsAuthCookie.SetAuthCookie(用户名,持久性)
设置AuthCookie,请参见

并在web.config中设置适当的超时

  <system.web>
     <authentication mode="Forms">
             <forms timeout="10080" slidingExpiration="true"/>
     </authentication>
  </system.web>

每次IIS回收应用程序时,都会生成一个新的机器密钥。您的身份验证票证是使用该机器密钥签名的,因此当生成新的身份验证票证时,身份验证票证将不再被识别。您需要在web.config中设置静态机器密钥


感谢您的回复,但我使用的是
GetAuthCookie
,它的功能与此相同,但返回的是cookie,而不是为我设置cookie。这听起来很正确。我检查了我的应用程序池,它被设置为每29小时循环一次,这是匹配的。我是否只需将生成的密钥放入web.config的配置部分?是的,只需将其粘贴到web.config的
部分,好的,这就是答案。我已将其推送到服务器并回收了应用程序池,我仍保持登录状态。但问题是我不能再调试我的解决方案了。我发现这个错误
在应用程序级别之外使用注册为allowDefinition='MachineToApplication'的节是错误的  <system.web>
     <authentication mode="Forms">
             <forms timeout="10080" slidingExpiration="true"/>
     </authentication>
  </system.web>