2017-04-22 74 views
1

我用会员与此代码来创建一个永久性的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> 

我希望用户只需点击注销按钮即可注销,不想在一段时间后退出。

我该如何解决我的问题?

+0

目前,您已将窗体身份验证cookie的有效性设置为'43200'分钟,且过期失效。这意味着如果在这段时间内没有来自用户的活动,则cookie将失效。这段时间不适合你吗?或者您需要无限超时,以便cookie永不过期? –

+0

@DarinDimitrov这是一个足够的时期,但不工作。例如,它在30分钟后不到一个月后过期 – Mike

+0

我看到你也在使用''。您的身份验证是否依赖于此会话中存储的某些值?如果是这样,那么你不应该使用'InProc'。因为这意味着您的会话值存储在AppDomain的内存中。正如您所知,AppDomain可随时由IIS卸载。例如,如果没有任何活动或者达到某些CPU或内存水印。如果您希望它们能够在AppDomain重新启动(可以在任何时间,无法控制的情况下发生)下使用,您将不得不为会话使用超出程序的存储机制。 –

回答