asp.net – 使用基于令牌的身份验证时,Web API 2 AccessFailedCo
发布时间:2020-12-16 07:25:22  所属栏目:asp.Net  来源:网络整理 
            导读:我使用带有Identity2.0 AccessFailedCount的Webapi,LockoutEndDateUtc没有在无效的用户名和密码上进行检测.我实现了WebAPI提供的基于令牌的身份验证.请帮忙 . 这是代码片段 using (UserManagerApplicationUser userManager = userManagerFactory) { Applicat
                
                
                
            | 
                         
 我使用带有Identity2.0 AccessFailedCount的Webapi,LockoutEndDateUtc没有在无效的用户名和密码上进行检测.我实现了WebAPI提供的基于令牌的身份验证.请帮忙 . 
  
  
这是代码片段 using (UserManager<ApplicationUser> userManager = userManagerFactory)
        {
            ApplicationUser user = await userManager.FindAsync(context.UserName,context.Password);
            if (user == null)
            {
                context.SetError("invalid_grant","The user name or password is incorrect.");
                return;
            }
            if (await userManager.IsLockedOutAsync(user.Id))
            {
                context.SetError("lock_out","The account is locked.");
                return;
            }
            if (!userManager.IsEmailConfirmed(user.Id))
            {
                context.SetError("inactive_user","The user is not active. Please check your Register Email to verify.");
                return;
            }
            ClaimsIdentity oAuthIdentity = await userManager.CreateIdentityAsync(user,context.Options.AuthenticationType);
            ClaimsIdentity cookiesIdentity = await userManager.CreateIdentityAsync(user,CookieAuthenticationDefaults.AuthenticationType);
            AuthenticationProperties properties = CreateProperties(user);
            AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity,properties);
            context.Validated(ticket);
            context.Request.Context.Authentication.SignIn(cookiesIdentity);
        }
解决方法
 最后我已经解决了这个代码 
  
  
  
        // To lock the user with userName ---- setting of maximum access 5 in IdentityConfig.cs File 
ApplicationUser userToLock = await userManager.FindByNameAsync(context.UserName);
if (userToLock != null)
{
    await userManager.AccessFailedAsync(userToLock.Id);
} 
 现在访问AccessFailedCount,LockoutEndDateUtc获取值 谢谢你的帮助.特别感谢@trailmax ……将我的想法转移到webapi (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
相关内容
- 如何阻止MVC缓存调用动作方法的结果?
 - asp.net-mvc – EF上下文管理
 - asp.net – 根据角色为某些用户提供更强的密码
 - asp.net-mvc – 带MVC剃刀的输入类型复选框
 - asp.net-mvc – 如何在Controller中使用依赖注入和存储库模
 - asp.net-core-mvc – 如何在Asp.Net Core中自定义Developer
 - asp.net-mvc – MVC 2 jQuery验证和ajax表单
 - ASP.NET MVC4会话状态存储用户名
 - 用户锁定.net 4.5.1 ASP.NET MVC 5
 - asp.net-mvc – 在MVC身份(2.0.1)中的regenerateIdentity/v
 
推荐文章
            站长推荐
            - asp.net-mvc – Asp.Net MVC Html助手扩展
 - asp.net-mvc – IE 11 SignalR不工作
 - asp.net – 带标题的Response.Redirect
 - asp.net – 无法转换类型为’System.Web.UI.Lite
 - asp.net-mvc – RazorEngine:不能使用Html.Raw
 - asp.net – 使用SqlMetal和Visual Studio时自动生
 - asp.net-mvc – 有一种方法我可以在ASP中调试路由
 - 如果在BackgroundWorker运行过程中关闭窗体…
 - Asp.Net Core API网关Ocelot
 - asp.net – Visual Studio 2012不发布项目
 
热点阅读
            