Reputation: 71
I am trying to find a good walkthrough or example of how to use the new Identity authorization system with added roles. When you create a new website in VS 2013 there is also an Account folder and in the database you have the tables also connected to roles. But all examples available are connected to MVC! Does anybody have a link to a good Identity users or programmers guide that does not use MVC?
Looking forward to any proposal in this matter.
Upvotes: 5
Views: 22774
Reputation: 55
I've found an answer on another page here to add users to roles by Tarzan. Here is the code:
internal class Security
{
ApplicationDbContext context = new ApplicationDbContext();
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;
}
}
}
Upvotes: 0
Reputation: 55
I am attempting to do the same exact thing. This is the tutorial that I'm using to help accomplish creating a role using web forms.
It branches off a previous project, but it gives a download link to the previous project to build upon. Hope this helps!
The only downside is it creates a brand new user and adds it into the new role instead of assigning a current user to it.
Upvotes: 1
Reputation: 731
Here is an excellent step-by-step significant informative tutorial as part of asp.net/webforms learning path.
It gives thorough knowledge & details like,
Update: Here is Asp.net Identity tutorial for web forms for empty project & existing web-forms. For roles customization, you can refer this article. Though it is in MVC 5 but it applies to asp.net web-forms as well.
Upvotes: 3