Ami*_*imi 5 asp.net asp.net-core-mvc .net-core asp.net-core asp.net-core-2.0
我正在尝试编写一个自定义身份验证管理器,该程序将处理我的ASP .Net Core 2.x应用程序中的用户登录和注销以及许多其他内容,但我始终处于困境。
我尝试了这篇Microsoft文章中建议的方式,但是当我尝试实现登录时,它显示了HttpContext does not contain a definition for SignOutAsync
错误。我有文章中建议的所有参考资料:
public async void SignIn(HttpContext httpContext, UserDbModel user, bool isPersistent = false)
{
ClaimsIdentity identity = new ClaimsIdentity(this.GetUserClaims(user), CookieAuthenticationDefaults.AuthenticationScheme);
ClaimsPrincipal principal = new ClaimsPrincipal(identity);
await HttpContext.SignInAsync(IdentityConstants.ApplicationScheme);
}
Run Code Online (Sandbox Code Playgroud)
下面的代码有效,但是已经过时了:
await HttpContext.Authentication.SignOutAsync(...)
Run Code Online (Sandbox Code Playgroud)
类中的引用:
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Authentication;
Run Code Online (Sandbox Code Playgroud)
这里缺少什么?也许这些扩展方法已在新版本中删除,如果是的话...我如何以正确的方式实现身份验证?
HttpContext
应该是对您中某个字段的引用,Controller
并且您不是在引用 a/the type HttpContext
。如果情况并非如此,那么这就是您的问题的原因,请更改您的代码以使用字段/变量而不是类型。
因此,如果httpContext
然后使用字段名称作为调用扩展方法是通过引用实例上的方法而不是类型来完成的,因为实例也作为扩展方法的第一个参数传入。
await httpContext.SignInAsync(IdentityConstants.ApplicationScheme);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3139 次 |
最近记录: |