Identity: Obsolete: options.Cookies.ApplicationCookie

Created on 22 Apr 2017  路  6Comments  路  Source: aspnet/Identity

After upgrading to 2.0 from a working ASP.NET CORE WebApp v1.1, I get an error on my setting of cookie values in Startup.cs:

Severity    Code    Description Project File    Line    Suppression State
Error   CS0619  'IdentityCookieOptions.ApplicationCookie' is obsolete: 'See https://go.microsoft.com/fwlink/?linkid=845470' WebAppCore  C:\Scott\POC2\WebAppCore\Startup.cs 105 Active

Here is my versions from *.cproj

    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeFrameworkVersion>2.0.0-preview2-002066-00</RuntimeFrameworkVersion>

Here is the code from Startup.cs

services.Configure<IdentityOptions>(options =>
            {
                // Password settings
                options.Password.RequireDigit = true;
                options.Password.RequiredLength = 8;
                options.Password.RequireNonAlphanumeric = true;
                options.Password.RequireUppercase = true;
                options.Password.RequireLowercase = true;

                // Lockout settings
                options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
                options.Lockout.MaxFailedAccessAttempts = 10;
                options.Lockout.AllowedForNewUsers = true;

                // Cookie settings
                options.Cookies.ApplicationCookie.CookieName = "FCS";
                options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromDays(150);
                options.Cookies.ApplicationCookie.LoginPath = "/Account/LogIn";
                options.Cookies.ApplicationCookie.LogoutPath = "/Account/LogOff";
                options.Cookies.ApplicationCookie.AccessDeniedPath = "/Account/AccessDenied";
                options.Cookies.ApplicationCookie.AutomaticAuthenticate = true;
                options.Cookies.ApplicationCookie.AuthenticationScheme = Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationDefaults.AuthenticationScheme;
                options.Cookies.ApplicationCookie.ReturnUrlParameter = Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationDefaults.ReturnUrlParameter;

                // User settings
                options.User.RequireUniqueEmail = true;
            });
discussion

Most helpful comment

All 6 comments

Here is the list of installed packages:
<ItemGroup> <PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-preview1-24591" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.0-preview1-24591" /> <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="2.0.0-preview1-24591" /> <PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.0-preview1-24591" /> <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0-preview1-24591" /> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-preview1-24591" /> <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0-preview1-24591" /> <PackageReference Include="Microsoft.CodeAnalysis.Common" Version="2.1.0" /> <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.1.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0-preview1-24591" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0-preview1-24591" PrivateAssets="All" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0-preview1-24591" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-24591" PrivateAssets="All" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0-preview1-24591" PrivateAssets="All" /> <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.0.0-preview1-24591" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0-preview1-24591" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0-preview1-24591" PrivateAssets="All" /> <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0-preview1-24591" /> <PackageReference Include="Puma.Security.Rules" Version="1.0.4" /> </ItemGroup> <ItemGroup> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.1.0-preview4-final" /> <DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.0" /> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" /> </ItemGroup> <ItemGroup> <Folder Include="Views\ApplicationRole\" /> <Folder Include="Views\User\" /> </ItemGroup>

services.ConfigureApplicationCookie(options => options.AccessDeniedPath = "/Home/AccessDenied");

app.UseAuthentication();

https://github.com/aspnet/MusicStore/blob/4237a93ee8e258a39373ea62715e15fad382311c/samples/MusicStore/ForTesting/Mocks/StartupSocialTesting.cs

Due to Authentication 2.0, cookie options instances no longer can be stored in IdentityOptions, yo ucan configure them as @opalrigby834 mentioned.

How to set CookieName?

It is now on the CookieBuilder instead of CookieAuthenticationOptions. CookieBuilder lives in HttpAbstractions.

Was this page helpful?
0 / 5 - 0 ratings