asp.net-coreasp.net-core-mvctoken

Is the ConfigureApplicationCookie(...) designed to allow us to configure an existing cookie by default in the default scheme (Cookies)?


I was implementing the remember me option in a login form in an asp.net core MVC project, so I ran into the topic of saving a token in a cookie and that a cookie must exist in a scheme. As I understand, there is a default scheme which is named as "Cookies" by default.

I'm currently confused about the ConfigureApplicationCookie(...) method, as I don't know to which scheme is that cookie that we are configuring related to.


Solution

  • You could check the source codes for the ConfigureApplicationCookie , this is the Identity library codes:

    The source codes as below, it used to configure the Identity.Application scheme. Not your added cookie scheme.

    Codes:

    /// <summary>
    /// Configures the application cookie.
    /// </summary>
    /// <param name="services">The services available in the application.</param>
    /// <param name="configure">An action to configure the <see cref="CookieAuthenticationOptions"/>.</param>
    /// <returns>The services.</returns>
    public static IServiceCollection ConfigureApplicationCookie(this IServiceCollection services, Action<CookieAuthenticationOptions> configure)
        => services.Configure(IdentityConstants.ApplicationScheme, configure);
    

    The result for the IdentityConstants.ApplicationScheme is as below:

    enter image description here