3

I have an existing production ASP.NET Core 1.1 project that I have upgraded to ASP.NET Core 2.

I set the ASP.NET Core identity authentication cookie like this in ASP.NET Core 1.1 to 2 hours

public void ConfigureServices(IServiceCollection services)
{

    services.AddIdentity<ApplicationUser, ApplicationRole>(options =>
    {
        options.Cookies.ApplicationCookie.CookieName = "MyApp";
        options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromMinutes(120);
     })
    .AddEntityFrameworkStores<MyDbContext, Guid>()
    .AddDefaultTokenProviders();

However in ASP.NET 2.0 Core the Cookies property has been removed from the AddIdentity option

1 Answer 1

4

If you want to tweak Identity cookies, they're no longer part of IdentityOptions. You will have use services.ConfigureApplicationCookie like this-

    public void ConfigureServices(IServiceCollection services)
    {
        ....
        services.ConfigureApplicationCookie(options => {
            options.CookieName = "MyApp";
            options.ExpireTimeSpan = TimeSpan.FromMinutes(120);
        });
        ....
    }

Note: CookieName property is obsolete and will be removed in a future version. The recommended alternative is Cookie.Domain.

Sign up to request clarification or add additional context in comments.

1 Comment

How will it now the above timeout is linked to my identity cookie and not some other cookie like if I make use of session cookie?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.