【问题标题】:When I upgrade from ASP.NET Core 1.x to 2.0, what is the replacement for IdentityCookieOptions?当我从 ASP.NET Core 1.x 升级到 2.0 时,IdentityCookieOptions 的替代品是什么?
【发布时间】:2017-12-25 09:30:56
【问题描述】:

我有一个 ASP.NET Core 1.1 应用程序,其代码使用此 API:

Microsoft.AspNetCore.Identity.IdentityCookieOptions

当我尝试升级到 ASP.NET Core 2.0 时,编译器给了我这个错误:

错误 CS0246:找不到类型或命名空间名称“IdentityCookieOptions”(您是否缺少 using 指令或程序集引用?)

ASP.NET Core 2.0 中的等效 API 是什么?

【问题讨论】:

  • 希望有人会为此添加公告。我找不到,只好翻遍 git 历史来找到变化。
  • 好吧,nate 指出了一些变化。从本质上讲,正如Auth 2.0 Changes / Migration 中所指出的,中间件方法已完全放弃。因此,所有UseXxxAuthentication() 方法都被删除,因此IdentityCookieOptions 和常量也被移至静态,正如 nate 指出的那样,IdentityCookieOptions 只是 Cookie 身份验证配置 + 常量的持有者。这是自后期 1.0 Beta 以来最大的重大变化之一恕我直言
  • 是的,这可能是此次更改的最佳公告。 1.1 和 2.0 之间发生了很多变化

标签: c# asp.net-core


【解决方案1】:

此 API 已在此更改中删除:https://github.com/aspnet/Identity/pull/1188

在大多数情况下,您很可能还是使用了默认值。您可以将IdentityCookieOptions 替换为IdentityConstants。如果您已自定义此值,您可能需要找到另一种方法将您的自定义方案名称流入适当的 SignInManager 调用(以及任何其他使用身份验证方案的地方)。

例子:

// old
IdentityCookieOptions.ApplicationScheme
IdentityCookieOptions.ApplicationCookieAuthenticationScheme 
// new
IdentityConstants.ApplicationScheme

// old
IdentityCookieOptions.ExternalScheme 
IdentityCookieOptions.ExternalCookieAuthenticationScheme
//new
IdentityConstants.ExternalScheme

//old
IdentityCookieOptions.TwoFactorRememberMeScheme
IdentityCookieOptions.TwoFactorRememberMeCookieAuthenticationScheme 
//new
IdentityConstants.TwoFactorRememberMeScheme

//old
IdentityCookieOptions.TwoFactorUserIdScheme
IdentityCookieOptions.TwoFactorUserIdCookieAuthenticationScheme 
//new
IdentityConstants.TwoFactorUserIdScheme

【讨论】:

  • 是否可以在 Startup.cs ConfigureServices 中设置这些 IdentityConstants?如果是,该怎么做?
猜你喜欢
  • 2018-07-08
  • 1970-01-01
  • 1970-01-01
  • 2018-01-28
  • 1970-01-01
  • 2018-05-31
  • 1970-01-01
  • 1970-01-01
  • 2018-04-13
相关资源
最近更新 更多