asp.net-core - 使用 ASP.NET 5 Cookie 身份验证的 Context.Response.SignIn() 的命名空间是什么

标签 asp.net-core

我们正在向新的 ASP.NET 5 应用程序添加 cookie 身份验证。 (目前使用 Beta 7)

我们将其添加到 Startup.cs:

//Use cookie authentication
app.UseCookieAuthentication(options => {
    options.LoginPath = new PathString("/Login");
    options.AutomaticAuthentication = true;
});

并且[Authorize]属性工作正常,重定向到登录页面。

在我们的 Login() Controller 方法中,我们正在创建声明和身份:

var claims = new List<Claim>();
claims.Add(new Claim("name", loginRequest.Username));

var identity = new ClaimsIdentity(claims.ToArray(),
    CookieAuthenticationDefaults.AuthenticationScheme);

作为最后一步,我们尝试调用 SignIn() 方法。

Context.Response.SignIn(identity); //what is the namespace for SignIn()??

但是我们找不到 SignIn() 方法的命名空间。我们的目标是使用最简单的解决方案,而不需要完整的身份框架。 (尽管如果有必要让 SignIn() 管道正常工作,我可以引用它。)

文档中提到的 SignIn() 方法的命名空间是什么?

最佳答案

我想通了 - 看起来我正在使用一些过时的文档。我应该像这样调用 SignIn() :

await Context.Authentication.SignInAsync(
    CookieAuthenticationDefaults.AuthenticationScheme, 
    new ClaimsPrincipal(identity));

This articlesimplified example他创造的东西非常有帮助。谢谢!

关于asp.net-core - 使用 ASP.NET 5 Cookie 身份验证的 Context.Response.SignIn() 的命名空间是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32464207/

相关文章:

c# - 不引用实现的 ASP.NET Core 依赖注入(inject)

c# - ASP.Net Core 文件上传进度 session

docker - 如何在 Docker 镜像中运行 Signalr Blazor 客户端的 StartAsync 连接?

c# - 当Action <SomeObject>的参数类型时实例化对象的对象

c# - ASP.NET Core 如何让 UserManager 在 Controller 中工作?

javascript - React props intellisense 与 ASP .NET Core

c# - 如何验证 ASP.NET Core 中的 DI 容器?

asp.net-mvc - ASP.NET 5 IsPost 消失了吗?

c# - 使用 Microsoft Graph token 通过 Jwt Bearer token 保护 ASP.NET Core Web API

asp.net-core - ASP.Net Core 1.1 - 迁移失败