【问题标题】:OWIN Authentication And TimeoutOWIN 身份验证和超时
【发布时间】:2018-01-12 18:32:17
【问题描述】:

我正在使用带有 OWIN 身份验证的 MVC 5。 这是我的 StartUp.cs 的代码。

    public void ConfigureAuth(IAppBuilder app)
    {
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            ExpireTimeSpan = new TimeSpan(60000000000)
        });
        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);


    }

过期时间设置为 60000000000 纳秒。

现在的要求是当cookie过期时,我需要重定向到登录屏幕。

怎么做?

【问题讨论】:

  • 只是为了好奇,TimeSpan的单位是100纳秒单位,所以应该是60000000000“100纳秒”单位。 1 纳秒 = 1/1000000 毫秒。 100 纳秒 = 1/10000 毫秒

标签: owin


【解决方案1】:

希望这将有助于调试... 错误在 web.config 文件中

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

这里的名称 Forms authenticationModule 是一个错字。应该是

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

瞧,它开始工作了。

【讨论】:

    【解决方案2】:

    我发现this 的例子更好:

    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Account/Login"),
        Provider = new CookieAuthenticationProvider
        {
            OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                validateInterval: TimeSpan.FromMinutes(15),
                regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
        },
        SlidingExpiration = false,
        ExpireTimeSpan = TimeSpan.FromMinutes(30)
    });
    

    将上面的代码粘贴到 App_Start 文件夹中的 Startup.Auth.cs 文件中。

    【讨论】:

      猜你喜欢
      • 2015-09-23
      • 2023-04-05
      • 1970-01-01
      • 2015-07-18
      • 2018-06-04
      • 1970-01-01
      • 1970-01-01
      • 2013-09-20
      • 2017-03-06
      相关资源
      最近更新 更多