Skip to content

.Net Core Identity application cookie is being deleted after 30 minutes while cookie's age is 30 days #48504

@hukumrat

Description

@hukumrat

Hello,
I use .net core identity for authentication and authorization in my project. I set .AspNetCore.Identity.Application cookie's expiration date after 30 days in controller:

var checkPasswordResult =
    await _signInManager.CheckPasswordSignInAsync(user, model.Password, lockoutOnFailure: true);

if (checkPasswordResult.Succeeded)
{
    var authenticationProperties = new AuthenticationProperties();

    if (model.RememberMe)
    {
        authenticationProperties.IsPersistent = true;
        authenticationProperties.ExpiresUtc = DateTimeOffset.UtcNow.AddDays(30);
        authenticationProperties.AllowRefresh = true;
    }

    await _signInManager.SignInAsync(user, authenticationProperties);
}

And my Startup:

services.AddAuthentication(IdentityConstants.ApplicationScheme)
        .AddCookie(options =>
        {
            options.LoginPath = "/Account/LogIn";
            options.LogoutPath = "/Account/LogOut";
            options.AccessDeniedPath = "/Account/AccessDenied";
            options.ExpireTimeSpan = TimeSpan.FromDays(30);
            options.SlidingExpiration = true;
        });

After login I can see it is set correctly:
241736578-2171d229-8d34-4e80-a079-c10e558171fe

Somehow, when I close browser and open it after 30 minutes, .AspNetCore.Identity.Application cookie is being deleted. I checked it in my local in production environment and I saw that cookie is not being deleted.

I don't have any custom middleware which will effect this cookie and I don't have any custom configuration which will delete any cookie after any minutes in server.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Author FeedbackThe author of this issue needs to respond in order for us to continue investigating this issue.Needs: ReproIndicates that the team needs a repro project to continue the investigation on this issueStatus: No Recent Activityarea-identityIncludes: Identity and providers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions