asp.net-identity

ASP.NET Core Identity 2: User.IsInRole always returns false

强颜欢笑 提交于 2020-01-23 06:51:26
问题 The question: I call RoleManager.CreateAsync() and RoleManager.AddClaimAsync() to create roles and associated role claims. Then I call UserManager.AddToRoleAsync() to add users to those roles. But when the user logs in, neither the roles nor the associated claims show up in the ClaimsPrincipal (i.e. the Controller's User object). The upshot of this is that User.IsInRole() always returns false, and the collection of Claims returned by User.Claims doesn't contain the role claims, and the

ASP.NET 5 MVC6 User.GetUserId() returns incorrect id

ε祈祈猫儿з 提交于 2020-01-23 01:33:32
问题 I have simple project in ASP.NET 5 with one registered user. I have tried to get id of current logged user by extension method GetUserId() from using System.Security.Claims namespace. Unfortunately this method returns me not existing id and i don't know why. Here is my simple code: var currentUserId = User.GetUserId(); Method result: Database: 回答1: More than likely you're getting an old auth ticket that is still valid OR your getting an authentication ticket for another site your running

UserCookieAuthentication in Mono 3.4.1

安稳与你 提交于 2020-01-22 09:51:05
问题 When ever I add the line below to my Startup class I get the exception below. This is a self hosted exe running from mono (Ubuntu). It works fine in windows. I've narrowed it down the UseCookieAuthentication call. I can instantiate the options without any issue. Any idea what is going on here? I have aspnet Identity working and EF6/MySql. app.UseCookieAuthentication(new CookieAuthenticationOptions()); Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown

ResetPassword Token How and where is it stored?

倖福魔咒の 提交于 2020-01-20 06:42:47
问题 I've been trying to understand how the reset password & account confirmation works in ASP.NET Identity. I'd just like to know if the Tokens are being stored and if so, where? The links I receive when I'm using the password reset feature look something like this http://localhost:1470/Account/ResetPassword?userId=a8b1389c-df93-4dfc-b463-541507c1a4bc&code=yhUegXIM9SZBpPVbBtv22kg7NO7F96B8MJi9MryAadUY5XYjz8srVkS5UL8Lx%2BLPYTU6a6jhqOrzMUkkMyPbEHPY3Ul6%2B%2F0s0qQvtM

MVC Identity wants to insert Null into table when value is not Null

*爱你&永不变心* 提交于 2020-01-17 13:52:10
问题 I just recently posted a question regarding adding properties to ApplicationUsers, and now this question follows from that: So now the FirstName and LastName properties for ApplicationUser are fields in the AspNetUsers table. But when I go to register as a new user, I get this error: System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'LastName', table 'aspnet-CustomUserProps-20151019035309.dbo.AspNetUsers'; column does not allow nulls. INSERT fails. This is my

MVC Identity wants to insert Null into table when value is not Null

南楼画角 提交于 2020-01-17 13:49:07
问题 I just recently posted a question regarding adding properties to ApplicationUsers, and now this question follows from that: So now the FirstName and LastName properties for ApplicationUser are fields in the AspNetUsers table. But when I go to register as a new user, I get this error: System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'LastName', table 'aspnet-CustomUserProps-20151019035309.dbo.AspNetUsers'; column does not allow nulls. INSERT fails. This is my

How to retrieve user details from database and display in a view [MVC 5 application,,Identity User]

白昼怎懂夜的黑 提交于 2020-01-17 02:20:12
问题 I just started creating an mvc 5 application ,I'm using default Identity user database for user data management,But I added some more fields like First Name ,Last Name ,Email Id to this database using migration,Now I need to display this all detail in a view page (as a profile page) ,but I don't know how to retrieve Identity user data from default database ,I am a new mvc developer can you help me my model class namespace WebApp.Models { public class ExternalLoginConfirmationViewModel {

Retrieve Role for a User in the DAL using ASP.NET Identity

不问归期 提交于 2020-01-16 18:44:11
问题 I have a bog-standard implementation of Users and Roles using ASP.NET Identity: public class User : IdentityUserBase { } public class Role : IdentityRoleBase { } public class UserRole : IdentityUserRoleBase { } I need a property or method in the User class that returns the (first) role of the user (in my app, each user can only have one): public class User : IdentityUserBase { // ... public Role GetRole() { return this.Roles.FirstOrDefault(); // this actually returns a UserRole object, with

How do I get the List of Role and Number of users in them asp.net mvc

倖福魔咒の 提交于 2020-01-16 08:51:04
问题 Please how do I get the list of roles, along with the number of users having the role? something like this I have tried this var users = allusers.Where(x=>x.Roles.Select(role => role.Name).Contains("User")).count; but this is just for one role. I need it for all the roles, and when a new role is added in the db, it should also add to the list. Thanks 回答1: Following code will be helpful to you. var result = ( from r in userManager.UserRoles join u in userManager.Users on r.UserId equals u.Id

JWT Authentication by role claims in ASP.NET core Identity

给你一囗甜甜゛ 提交于 2020-01-15 09:41:29
问题 How I can authenticate user by claims, which contains in user roles? In Startup.cs : services.AddAuthorization(options => { options.AddPolicy("CanEdit", policy => policy.RequireClaim("CanEdit")); }); And in login controller I have: private async ValueTask<JwtSecurityToken> GetJwtSecurityToken(ApplicationUser user){ //var totalClaims = new List<Claim>(); //var userRoles = await _userManager.GetRolesAsync(user); //foreach (var role in userRoles) { // var roleClaims = await _roleManager