对类型 'AuthenticationTicket' 的引用声称它在 'Microsoft.AspNetCore.Authentication' 中定义,但找不到
Reference to type 'AuthenticationTicket' claims it is defined in 'Microsoft.AspNetCore.Authentication', but it could not be found
我有一个 ASP.NET Core 2 应用程序,现在我在从 Core 1x 迁移代码时遇到了一些问题。这里我们有一小段代码。我有这个错误,有人可以告诉我这件事是否有任何改变吗?
PS:四个错误都一样:
Reference to type 'AuthenticationTicket' claims it is defined in
'Microsoft.AspNetCore.Authentication', but it could not be found.
[errors in the code][1]
enter image description here
private async Task<AuthenticationTicket> CreateTicketAsync(OpenIdConnectRequest request, ApplicationUser user, AuthenticationProperties properties = null)
{
// Create a new ClaimsPrincipal containing the claims that
// will be used to create an id_token, a token or a code.
var principal = await _signInManager.CreateUserPrincipalAsync(user);
// Create a new authentication ticket holding the user identity.
var ticket = new AuthenticationTicket(principal, new AuthenticationProperties(), OpenIdConnectServerDefaults.AuthenticationScheme);
ticket.SetResources(request.GetResources());**// ERROR IN THIS LINE**
//if (!request.IsRefreshTokenGrantType())
//{
// Set the list of scopes granted to the client application.
// Note: the offline_access scope must be granted
// to allow OpenIddict to return a refresh token.
ticket.SetScopes(new[] **// ERROR IN THIS LINE**
{
OpenIdConnectConstants.Scopes.OpenId,
OpenIdConnectConstants.Scopes.Email,
OpenIdConnectConstants.Scopes.Profile,
OpenIdConnectConstants.Scopes.OfflineAccess,
OpenIddictConstants.Scopes.Roles
}.Intersect(request.GetScopes())); **// ERROR IN THIS LINE**
//}
}
更新:
Nuget references
您的参考列表表明您正在混合为 ASP.NET 核心 1.x 设计的软件包和需要 2.x 的软件包。由于在 2 ASP.NET 核心包之间引入了巨大的变化,为 1.x 构建的与身份验证相关的包不太可能与 2.0 一起使用。
尝试更新您的软件包以使用 ASP.NET Core 2.0 兼容版本。 AspNet.Security.OAuth.Validation
、AspNet.Security.OpenIdConnect.Primitives
、AspNet.Security.OpenIdConnect.Server
都已更新以支持新的身份验证 API(注意:您不需要引用最后 2 个包,因为它们由 OpenIddict 间接引用)。
我有一个 ASP.NET Core 2 应用程序,现在我在从 Core 1x 迁移代码时遇到了一些问题。这里我们有一小段代码。我有这个错误,有人可以告诉我这件事是否有任何改变吗? PS:四个错误都一样:
Reference to type 'AuthenticationTicket' claims it is defined in 'Microsoft.AspNetCore.Authentication', but it could not be found.
[errors in the code][1]
enter image description here
private async Task<AuthenticationTicket> CreateTicketAsync(OpenIdConnectRequest request, ApplicationUser user, AuthenticationProperties properties = null)
{
// Create a new ClaimsPrincipal containing the claims that
// will be used to create an id_token, a token or a code.
var principal = await _signInManager.CreateUserPrincipalAsync(user);
// Create a new authentication ticket holding the user identity.
var ticket = new AuthenticationTicket(principal, new AuthenticationProperties(), OpenIdConnectServerDefaults.AuthenticationScheme);
ticket.SetResources(request.GetResources());**// ERROR IN THIS LINE**
//if (!request.IsRefreshTokenGrantType())
//{
// Set the list of scopes granted to the client application.
// Note: the offline_access scope must be granted
// to allow OpenIddict to return a refresh token.
ticket.SetScopes(new[] **// ERROR IN THIS LINE**
{
OpenIdConnectConstants.Scopes.OpenId,
OpenIdConnectConstants.Scopes.Email,
OpenIdConnectConstants.Scopes.Profile,
OpenIdConnectConstants.Scopes.OfflineAccess,
OpenIddictConstants.Scopes.Roles
}.Intersect(request.GetScopes())); **// ERROR IN THIS LINE**
//}
}
更新: Nuget references
您的参考列表表明您正在混合为 ASP.NET 核心 1.x 设计的软件包和需要 2.x 的软件包。由于在 2 ASP.NET 核心包之间引入了巨大的变化,为 1.x 构建的与身份验证相关的包不太可能与 2.0 一起使用。
尝试更新您的软件包以使用 ASP.NET Core 2.0 兼容版本。 AspNet.Security.OAuth.Validation
、AspNet.Security.OpenIdConnect.Primitives
、AspNet.Security.OpenIdConnect.Server
都已更新以支持新的身份验证 API(注意:您不需要引用最后 2 个包,因为它们由 OpenIddict 间接引用)。