如何自动防止退出?

时间:2017-04-22 10:06:37

标签: c# asp.net asp.net-mvc

我使用Membership和此代码创建了一个持久性Cookie,以防止用户在登录后自动注销:

FormsAuthentication.SetAuthCookie(user.Id.ToString(),true);

并在web.config文件中使用此设置:

<authentication mode="Forms">
  <forms name=".mywebsite" cookieless="UseCookies" loginUrl="~/Account/SignIn" defaultUrl="~/ManagePanel/Statistic" slidingExpiration="true" protection="All" path="/" timeout="43200" />
</authentication>
<sessionState mode="InProc" timeout="43200" />
<httpModules>

<modules>
  <remove name="FormsAuthenticationModule" />
  <add name="FormsAuthenticationModule" type="System.Web.Security.FormsAuthenticationModule" />
  <remove name="UrlAuthorization" />
  <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
  <remove name="DefaultAuthentication" />
  <add name="DefaultAuthentication" type="System.Web.Security.DefaultAuthenticationModule" />
</modules>

我希望用户只有在点击退出按钮时才能退出,并且暂时不想退出。

如何解决我的问题?

1 个答案:

答案 0 :(得分:0)

解决方案是the comment by Darin Dimitrov中建议的解决方案:

  

您可以尝试在web.config中明确设置machineKey:   https://stackoverflow.com/a/3855874/29407也许钥匙会以某种方式改变   在远程主机上,您的应用程序无法解密表单   身份验证cookie。