Authentication and OWIN Timeout

I am using MVC 5 with OWIN authentication. Here is the code for my 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);


    }

The expiration time is set to 60000000000 nanoseconds.

Now that the cookie has expired, I need to redirect to the login screen.

How to do it?

+3
source share
2 answers

Hope this helps someone debug ... Error in web.config file

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

here the name Forms authenticationModule is a typo. it should be

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

And he began to work.

+3
source

I found this example better:

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)
});

Paste the above code into the Startup.Auth.cs file from the App_Start folder.

0
source

All Articles