title: ASp.Net Identity Role manager
body: <p>I am using Visual Studio 2013. I have a ASP.net (vb) Webforms site with asp.net identity. I trying to create  a page that manages User role and create roles. I cant find any help online for this when it comes to web forms.  This code works for asp.net membership but not for Identity. Here is my code.
  Please help Thanks.</p>
  
  <pre><code>Imports Microsoft.AspNet.Identity
  Imports Microsoft.AspNet.Identity.EntityFramework
  Imports Microsoft.AspNet.Identity.Owin
  Imports Microsoft.Owin.Security
  Imports Owin
  
  Partial Class AssignRoles
      Inherits System.Web.UI.Page
  
      Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
          Roles.AddUserToRole(DropDownList5.SelectedValue, DropDownList6.SelectedValue)
          Label1.Text = DropDownList5.SelectedValue + " Was added to the " + DropDownList6.SelectedValue + " Role."
      End Sub
  
      Protected Sub btnremoverole_Click(sender As Object, e As EventArgs) Handles btnremoverole.Click
          Roles.RemoveUserFromRole(DropDownList3.SelectedValue, DropDownList4.SelectedValue)
          Label1.Text = DropDownList3.SelectedValue + " Was removed from the " + DropDownList4.SelectedValue + " Role."
      End Sub
  
      Protected Sub CreateRole_Click(sender As Object, e As EventArgs) Handles CreateRole.Click
          Dim createRole As String = RoleTextBox.Text
  
          Try
              If Roles.RoleExists(createRole) Then
                  Msg.Text = "Role '" &amp; Server.HtmlEncode(createRole) &amp; "' already exists. Please specify a different role name."
                  Return
              End If
  
              Roles.CreateRole(createRole)
  
              Msg.Text = "Role '" &amp; Server.HtmlEncode(createRole) &amp; "' created."
  
              ' Re-bind roles to GridView.
  
          Catch
              Msg.Text = "Role '" &amp; Server.HtmlEncode(createRole) &amp; "' &lt;u&gt;not&lt;/u&gt; created."
          End Try
      End Sub
  End Class
  </code></pre>
  
  <p>Here is the Markup code</p>
  
  <pre><code>&lt;%@ Page Title="Admin Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true"CodeBehind="AssignRoles.aspx.vb" Inherits="Conflict_Minerals.AssignRoles" %&gt;
  
  &lt;asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"&gt;
  
  
  
      &lt;div class="row"&gt;
          &lt;div class="col-md-12"&gt;
              &lt;h2&gt;Admin Panel&lt;/h2&gt;
              &lt;br /&gt;
          &lt;/div&gt;
          &lt;div class="col-md-8"&gt;
              &lt;asp:Label ID="Label3" runat="server" Text="Add user to role:  "&gt;&lt;/asp:Label&gt;
              &lt;asp:DropDownList ID="DropDownList5" runat="server" DataSourceID="SqlDataSource1" DataTextField="UserName" DataValueField="UserName"&gt;
              &lt;/asp:DropDownList&gt;
              &lt;asp:DropDownList ID="DropDownList6" runat="server" DataSourceID="SqlDataSource2" DataTextField="Name" DataValueField="Name"&gt;
              &lt;/asp:DropDownList&gt;
              &lt;asp:Button ID="Button1" runat="server" Text="Add user to role" /&gt;
          &lt;/div&gt;
          &lt;div class="col-md-8"&gt;
              &lt;br /&gt;
              &lt;br /&gt;
              &lt;br /&gt;
              &lt;asp:Label ID="Label1" runat="server" Text="Label"&gt;&lt;/asp:Label&gt;
              &lt;br /&gt;
              &lt;br /&gt;
              &lt;br /&gt;
              &lt;asp:Label ID="Label2" runat="server" Text="Remove user from role:   "&gt;&lt;/asp:Label&gt;
  
              &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource1" DataTextField="UserName" DataValueField="UserName"&gt;
              &lt;/asp:DropDownList&gt;
               &amp;nbsp&lt;asp:DropDownList ID="DropDownList4" runat="server" DataSourceID="SqlDataSource2" DataTextField="RoleName" DataValueField="RoleName"&gt;
              &lt;/asp:DropDownList&gt; &amp;nbsp
  
              &lt;asp:Button ID="btnremoverole" runat="server" Text="Remove user from role" Height="26px" /&gt;
  
              &lt;br /&gt;
              &lt;br /&gt;
              &lt;div&gt;
                  &lt;h2&gt;Manage Roles&lt;/h2&gt;
              &lt;/div&gt;
              &lt;br /&gt;
              &lt;asp:TextBox ID="RoleTextBox" runat="server"&gt;&lt;/asp:TextBox&gt;
              &lt;asp:Button ID="CreateRole" runat="server" Text="Create Role" /&gt;
              &lt;br /&gt;
              &lt;br /&gt;
              &lt;asp:Label ID="Msg" runat="server" Text="Label"&gt;&lt;/asp:Label&gt;
              &lt;br /&gt;
              &lt;br /&gt;
              &lt;br /&gt;
                  &lt;asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="&lt;%$ ConnectionStrings:DefaultConnection %&gt;" SelectCommand="SELECT [Name] FROM [vw_AspNetRoles]"&gt;&lt;/asp:SqlDataSource&gt;
                  &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:DefaultConnection %&gt;" SelectCommand="SELECT [UserName] FROM [AspNetUsers]"&gt;&lt;/asp:SqlDataSource&gt;
                  &lt;br /&gt;
              &lt;br /&gt;
  
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/asp:Content&gt;
  </code></pre>