ConfigureApplicationCookie(...) 的设计目的是为了允许我们在默认方案(Cookies)中默认配置一个现有的 cookie 吗?

问题描述 投票:0回答:1

我在一个asp.net core MVC项目的登录表单中实现了记住我选项,所以我遇到了在cookie中保存令牌的主题,并且cookie必须存在于方案中。据我了解,有一个默认方案,默认命名为“Cookies”。

我目前对

ConfigureApplicationCookie(...)
方法感到困惑,因为我不知道我们正在配置的 cookie 与哪个方案相关。

  • 它是 Cookies 方案中的 cookie吗?如果不是,它与哪个方案相关?
  • 它是默认存在并且我们配置它还是在我们调用该方法时创建?
asp.net-core asp.net-core-mvc token
1个回答
0
投票

您可以检查

ConfigureApplicationCookie
的源代码,这是身份库代码:

源码如下,用于配置

Identity.Application
方案。不是您添加的 cookie 方案。

代码:

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

IdentityConstants.ApplicationScheme
的结果如下:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.