我想向我的应用程序添加身份验证。 这是我的代码
using Microsoft.AspNetCore.Http;
using System;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Authentication;
using Microsoft.AspNetCore.Identity;
namespace OlegTarOpenId
{
public class OpenIdMiddleware
{
private readonly RequestDelegate _next;
public OpenIdMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
var claims = new[]
{
new Claim("name", "Oleg")
};
var claimsIdentity = new ClaimsIdentity(claims, "Google");
// Call the next delegate/middleware in the pipeline
await context.SignInAsync("Google", new ClaimsPrincipal(claimsIdentity));//<-- There is the error
await _next(context);
}
}
}
我将 Microsoft.AspNetCore.Authentication.Abstractions 添加到我的项目中。但我不知道为什么 context 没有看到扩展方法 SignInAsync。
最佳答案
SignInAsync
是一个扩展方法,位于 Microsoft.AspNetCore.Authentication.Abstractions
并位于 Microsoft.AspNetCore.Authentication
命名空间内。
就您而言,看起来您只需要添加 using
语句:
using Microsoft.AspNetCore.Authentication;
这与 ASP.NET Core Identity 和 Microsoft.AspNetCore.Identity
包是分开的。
关于c# - .netcore 2.2 Httpcontext 没有 SignInAsync,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53907684/