Net6: User add to role and move out role, role creation and deletion, etc. roles and membership use

Source: Internet
Author: User

The original Published time: 2008-07-30--from my Baidu article [imported by moving tools]

Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;

public partial class Admin_rolegroup:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Listbox1.datasource = Membership.getallusers ();
Listbox1.databind ();
Listbox2.datasource = Roles.getallroles ();
Listbox2.databind ();
}
}
protected void Button1_Click (object sender, EventArgs e)
{
string user = Listbox1.selectedvalue;
string role = Listbox2.selectedvalue;

if (! Roles.isuserinrole (user, role))
{
Roles.addusertorole (user, role);
}
Else
{
Response.Write ("User is in the role");
}
Listbox3.datasource = roles.getusersinrole (role);
Listbox3.databind ();
}

protected void button2_click (object sender, EventArgs e)
{
if (listbox3.items.count>0)
{
string user = Listbox3.selectedvalue;
string role = Listbox2.selectedvalue;

if (Roles.isuserinrole (user,role))
{
Roles.removeuserfromrole (User,role);
}
Else
{
Response.Write ("User is not in the role");
}
Listbox3.datasource = roles.getusersinrole (role);
Listbox3.databind ();
}
}
protected void Listbox2_selectedindexchanged (object sender, EventArgs e)
{
String Role=listbox2.selectedvalue;
Listbox3.datasource=roles.getusersinrole (role);
Listbox3.databind ();
}
}

-------------------------------------------------------------------------------------------------

Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;

Public partial class Admin_role:System.Web.UI.Page
{
    protected void Page_Load (object sender, EventArgs e)
    {
        if (! IsPostBack)
        {
             Listbox1.datasource = Roles.getallroles ();
            Listbox1.databind ();
       }

}
protected void Button1_Click (object sender, EventArgs e)
{
Roles.createrole (TextBox1.Text);
LISTBOX1.ITEMS.ADD (TextBox1.Text);
}
protected void button2_click (object sender, EventArgs e)
{
Roles.deleterole (Listbox1.selectedvalue);
ListBox1.Items.Remove (Listbox1.selecteditem);
}
}

Net6: User add to role and move out role, role creation and deletion, etc. roles and membership use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.