5

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.

user3162086
  • 71
  • 1
  • 1
  • 3

3 Answers3

3

Here is an excellent step-by-step significant informative tutorial as part of asp.net/webforms learning path.

It gives thorough knowledge & details like,

  • Create/Manage Roles
  • Assigning Roles to Users
  • Role-Based Configuration

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.

Palak Bhansali
  • 731
  • 4
  • 10
  • 4
    Thank you for your answer, but this tutorial uses the old Membership system of ASP.NET, not the new Identity that we got in VS 2013. – user3162086 Apr 26 '14 at 04:48
  • Thank you, that looks like something I can use. – user3162086 Apr 26 '14 at 17:16
  • 1
    Scott Allen has some nice tutorials on [his blog](http://odetocode.com/blogs/scott/archive/2014/01/20/implementing-asp-net-identity.aspx) about ASP.NET Identity. The information he provides is normally better than the ones you will find on the [official site](http://www.asp.net/identity). – Horizon_Net May 24 '14 at 11:22
  • yes, i just checked these articles & they are promising, one should consider to refer once. – Palak Bhansali May 30 '14 at 06:41
  • @PalakBhansali nice reference to a detailed article , which discusses stuff starting from Empty project , and that it discusses the OWIN as well.. – Irf Jun 08 '15 at 00:55
1

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.

http://www.asp.net/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/membership-and-administration

Borami O
  • 55
  • 7
0

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;
    }
}
}
Community
  • 1
  • 1
Borami O
  • 55
  • 7