The following are all SQL-Membership functions that I have been using in my website. I now want to port to IDENTITY, but I don't know what to replace them with:
The following are all SQL-Membership functions that I have been using in my website. I now want to port to IDENTITY, but I don't know what to replace them with:
According to your description, not all membership function could be mapped in the identity.
I suggest you could refer to below codes:
Roles.GetRolesForUser(username) returns list
-------------
public async string GetUserRole(string EmailID, string Password)
{
var user = await _userManager.FindAsync(EmailID, Password);
string rolename = await _userManager.GetRoles(user.Id).FirstOrDefault();
return rolename;
}
Roles.AddUserToRole(username,role)
-----------
internal void AddUserToRole(string userName, string roleName)
{
var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
try
{
var user = UserManager.FindByName(userName);
UserManager.AddToRole(user.Id, roleName);
context.SaveChanges();
}
catch
{
throw;
}
}
Roles.removeUserFromRole(username,role)
------------------
public async Task DeleteRolesAsync(List<string> deleteList, int? userId)
{
if (userId != null)
{
foreach (var roleName in deleteList)
{
IdentityResult deletionResult = await UserManager.RemoveFromRoleAsync(userId, roleName);
}
}
}
Membership.createuser()
----------------
var user = model.GetUser();
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
result = UserManager.AddToRole(user.Id, "User");
Membership.updateuser(newusers)
-----------------
// Get the existing student from the db
var user = (Student)UserManager.FindById(model.Id);
// Update it with the values from the view model
user.Name = model.Name;
user.Surname = model.Surname;
user.UserName = model.UserName;
user.Email = model.Email;
user.PhoneNumber = model.PhoneNumber;
user.Number = model.Number; //custom property
user.PasswordHash = checkUser.PasswordHash;
// Apply the changes if any to the db
UserManager.Update(user);
Best Regards,
Brando
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
61 Points
111 Posts
what are the IDENTITY counterparts to these outdated SQL-membership functions
Feb 22, 2018 11:00 AM|RateFor|LINK
The following are all SQL-Membership functions that I have been using in my website. I now want to port to IDENTITY, but I don't know what to replace them with:
My question is, are there IDENTITY counterparts to these, and if so, how do I look them up?
All-Star
53121 Points
23672 Posts
Re: what are the IDENTITY counterparts to these outdated SQL-membership functions
Feb 22, 2018 12:16 PM|mgebhard|LINK
Identity is just an API that provides access data stores. You need to read the reference docs.
https://www.asp.net/identity
The main APIs are the UserManager and SignInManager.
UserManager
https://msdn.microsoft.com/en-us/library/dn613290(v=vs.108).aspx
SignInManager
https://msdn.microsoft.com/en-us/library/dn896559(v=vs.108).aspx
Star
9831 Points
3120 Posts
Re: what are the IDENTITY counterparts to these outdated SQL-membership functions
Feb 23, 2018 02:25 AM|Brando ZWZ|LINK
Hi RateFor,
According to your description, not all membership function could be mapped in the identity.
I suggest you could refer to below codes:
Best Regards,
Brando