c# - .netcore 2.2 Httpcontext 没有 SignInAsync

标签 c# asp.net .net asp.net-core .net-core

我想向我的应用程序添加身份验证。 这是我的代码

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/

相关文章:

c# - 在 C# 中的 WinCE 上获取设备的 CPU 使用率和空闲 RAM

c# - 检查字符串是否排序

c# - 获取谷歌广告 ID 并限制广告

javascript - 从 JavaScript 函数触发 c# 事件

ASP.Net 自定义 session 状态管理

c# - 我可以从我的 ASP.NET 代码隐藏中调用一个 javascript 函数(来自经典 ASP)并获得它的结果吗?

c# - 使用线程的 ASP.NET MVC 自定义验证

c# - Silverlight MultiScaleImage 的源属性

c# - 如何集成 NLog 将日志写入 Azure Streaming 日志

c# - 我如何将代码更改为linq样式