我们正在为新的ASP.NET 5应用程序添加cookie身份验证.(目前使用Beta 7)
我们将此添加到Startup.cs:
//Use cookie authentication
app.UseCookieAuthentication(options => {
options.LoginPath = new PathString("/Login");
options.AutomaticAuthentication = true;
});
Run Code Online (Sandbox Code Playgroud)
并且该[Authorize]属性工作正常,重定向到登录页面.
在我们的Login()控制器方法中,我们正在创建声明和身份:
var claims = new List<Claim>();
claims.Add(new Claim("name", loginRequest.Username));
var identity = new ClaimsIdentity(claims.ToArray(),
CookieAuthenticationDefaults.AuthenticationScheme);
Run Code Online (Sandbox Code Playgroud)
作为最后一步,我们尝试调用SignIn()方法.
Context.Response.SignIn(identity); //what is the namespace for SignIn()??
Run Code Online (Sandbox Code Playgroud)
但是我们找不到SignIn()方法的命名空间.我们的目标是在没有完整身份框架的情况下使用最简单的解决方案.(虽然我可以在必要时引用它来使SignIn()管道工作.)
文档中提到的SignIn()方法的命名空间是什么?
我想通了 - 看起来我正在使用一些过时的文档.我应该像这样调用SignIn():
await Context.Authentication.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(identity));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
511 次 |
| 最近记录: |