MVC5 OWIN身份验证持久性在本地工作,但在发布时会很快超时

时间:2014-03-26 17:15:43

标签: session authentication cookies asp.net-mvc-5 owin

我的网站上使用MVC5 OWIN身份验证时遇到登录持久性问题。

我使用的是使用MVC5模板生成的代码。在VS上本地运行时,它会让我的用户长时间保持记录状态,但是,当我发布时,在服务器上它会在大约5分钟后注销。

我已经尝试过更改web.config

<system.webServer>
<modules>
  <remove name="FormsAuthenticationModule" />
</modules>
</system.webServer>

<system.webServer>
<modules>
  <remove name="FormsAuthentication" />
</modules>
</system.webServer>

但它不起作用。

尝试在Startup.Auth.cs中设置ExpireTimeSpan,但它也不起作用。

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
   AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
   LoginPath = new PathString("/Account/Login"),
   ExpireTimeSpan = new System.TimeSpan(20, 0, 0)
});

任何人都知道我可能做错了什么?

BTW,我没有使用ExternalLogins。

1 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,并按照你所做的相同步骤没有任何效果,甚至做了改变SlidingExpiration = true的建议。我终于想出来让它工作,我需要在我的Web.config中添加<machineKey/>。而中提琴,它的工作原理!现在我的机票在生产中保持身份验证。

相关问题