MVC5 OWIN身份验证持久性在生产中不起作用

时间:2015-07-01 00:29:23

标签: authentication asp.net-mvc-5 owin remember-me

我在网站上使用MVC5 OWIN身份验证时遇到登录持久性问题。用户将在5分钟后自动退出,但他们已经检查过我的选项。

在localhost上运行我的网站时,一切都运行正常,当我将网站发布到并行主机窗口时,问题就出现了。 我的登录代码:

AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent , ExpiresUtc = DateTime.Now.AddDays(14) }, identity);

My Startup.Auth.cs

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LoginPath = new PathString("/dang-nhap"),
    ExpireTimeSpan = new System.TimeSpan(14,0,0)
});

我在webconfig中的system.web部分,我已经包含了machineKey Tag

<system.web>
<customErrors mode="Off"/>
<machineKey />
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<pages>
  <namespaces>
    <add namespace="MvcPaging" />
  </namespaces>
</pages>

我的网站在我的电脑上发出的cookie,虽然过期时间已经设置为记录后的14天,但用户在5分钟后自动退出,因为缺乏声誉而无法发布图片。

1 个答案:

答案 0 :(得分:1)

“记住我”值应该转到上下文的ispersistant属性.Ticket。 AuthorizationCodeExpireTimeSpan是您需要设置的属性,可以在任何您想要的日期到期。此属性的默认有效期为5分钟,因此您的应用程序将在5分钟内超时。