Delete Roles how affect Users in that roles

Dear all,

 I know that Roles.deleteRoles(e.command.arguement).

If deleted the roles, how the users if they belong to that roles.

Would their roles also be dropped? I mean if looping the user roles. What will be the result.

0
rchiu5hk
4/21/2008 8:55:44 AM
asp.net.security 27051 articles. 1 followers. Follow

2 Replies
763 Views

Similar Articles

[PageSpeed] 58
Get it on Google Play
Get it on Apple App Store

hi

the delete will fails if there is a usrs assigend to the role ,

so before you want to delete the Role, you should remove the users from that role ,by using

Roles.RemoveUserFromRole(UserName,RoleToDelete)

 

http://msdn2.microsoft.com/en-us/library/aa478950.aspx

http://forums.asp.net/p/1181608/2004433.aspx


Regards,

Anas Ghanem.


Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

0
anas
4/21/2008 9:46:23 AM

Hi

Try this

 

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="DeleteRole.aspx.cs" Inherits="Admin_DeleteRole" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    Select Role you want to Delete:<br />
    <asp:ListBox ID="ListBox1" runat="server">
        <asp:ListItem Value="">-- Select --</asp:ListItem>
    </asp:ListBox>
    <br />
    <br />
    <asp:Button ID="btnDelete" runat="server" OnClick="btnDelete_Click" Text="Delete Role" />
    <br />
    <br />
    <asp:Label ID="lblMsg" runat="server" ForeColor="Red"></asp:Label><br />
    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Admin/AddRole.aspx">Add new Role</asp:HyperLink>
</asp:Content>

 and in code behind

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_DeleteRole : System.Web.UI.Page
{
    

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HyperLink1.Visible = false;
            string[] rolesname = Roles.GetAllRoles();
            ListBox1.DataSource = rolesname;
            ListBox1.DataBind();
        }
    }

    //* Delete Role button
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        try
        {
            string rolename = ListBox1.SelectedItem.Value;

            try
            {
                Roles.DeleteRole(rolename);
                lblMsg.Text = "Role has been deleted";
            }
            catch (Exception ex)
            {
                lblMsg.Text = ex.Message;
            }
        }
        catch (Exception ex)
        {
        }


        RefreshListBox();

    }
    // Method
    private void RefreshListBox()
    {
        ListBox1.SelectedIndex = -1;
        
        string[] rolesname = Roles.GetAllRoles();
        ListBox1.DataSource = rolesname;
        ListBox1.DataBind();

        //-- check if there is role
        if (ListBox1.Items.Count == 0)
        {
            lblMsg.Text = "There is no role";
            HyperLink1.Visible = true;
            btnDelete.Visible = false;
            ListBox1.Visible = false;
        }
        else
        {
            HyperLink1.Visible = false;
            btnDelete.Visible = true;
            ListBox1.Visible = true;

        }

    }

    
}
 
0
yasserzaid
5/14/2008 7:36:41 PM
Reply:

Similar Artilces:

Roles, roles, roles
Hey is it posible o have a role for a user to only update the content? I don't want that user to change skins or to make other admin changes... up I think if you allow a role to edit contents on a module level he wont be able to change anything else. Did you try that? cheers, erikErik van Ballegoij, The Netherlands if you allow a role to edit contents in a module lets say discussions module, then that role will be able to edit, delete the threads. so for a role to be able to add new thread only, do we need to write our own code?-keeara g------------------ keeara, see...

Creating User Account Without Default Security Role (Registered User Role)
  My DNN version is 3.1.1. The portal is set to Private Registration. Unauthenicated users have access to the basic pages of the site. We require my company's current customers to register and be approved to have access to all other pages that contain information restricted to them (the major part of the site). As you know, authorizing a user account applys the Registered User security role by default and this is how I control access to the customer areas.  We want to create a page that will be used by Marketing to allow potential customers by login to...

Duplicate Security Roles Showing up In Security Roles Manager
Anyone have any ideas?  We have had and instance of 3.0.13 with one child portal running for about a month now.  A few days ago our adminstrator noticed that we have duplicate entries for security roles. For example, the Security Roles Manager shows:Name Description Fee Every Period Trial Every Period Public Auto   Administrators Portal Administration         False False   Administrators Portal Administration         False False  Registered Users Registered Users    &n...

Manage Users For This Role / Manage Roles For This User Question
In the roles/user management pages there is a link called Manage Users For This Role and Manage Roles For This User respectively. I want non Admins to be able to see these pages, and currently I have it so that they can see the manage users and manage roles pages. However, when a non admin clicks on Manage Users For This Role or Manage Roles For This User link it does not display the control, just an empty page. I can get around this by giving edit rights to the page, but I do not want them to have edit rights for the page. Any ideas? Thanks  ...

Roles
I'm using a CreateUserwizard control and in the code behind for CreatedUser event I am trying to add the following single line of code:  Roles.AddUserToRole ... etc. However, Intellisense does not show Roles. (I am seeing RoleServiceManager but not Roles) Any idea why? I have Visual Studio 2008 and the project is targeting .NET Framework V3.5. Also, I have <roleManager enabled="true"> in the web.config file. Intellisence will work automatically, There is no relation to web.config, if any problem use,using System.Web.Security; ...

Changing User Roles / Deleteing User Accounts
While creating my site i have been using the test server built within visual studio to test my site. But now i want to upload my finished site but want to know how i can delete user accounts and set/change roles while it is online. I have been doing this within the ASp.net config site, but when i upload it how am i to change these? do i have to download the site off of the server and do it within VS or is there an easier way to do this? Thanks you just need to download the aspnet.mdf file and use asp.net configuration tool to prepare the database , then you can upload the database to t...

Problem : Get a list of user belonged to a role or to know if a user already has a role
What code can I write to know if a user belonged to a Role already ? and How can I get a list of a  user already in an existing role ? Please have a look at my code below : Protected Sub AddUsers_OnClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddUsersToRole.Click' I wanna add some code here to check if a user already belonged to a Role' Please insert your code here. Thanks a lot. ' A role must be selected If RolesListBox.SelectedItem Is Nothing Then Msg.Text = "Please select a role." Exit Sub End If ...

Populating roles and user/role mappings
I am using asp.net 2.0 and want to use role-based security using windows authentication and sqlserver.  I have setup my web.config to do this successfully and am able to add roles and user mappings via code.  However, at this point I don't want to build a page that allows the maintenance for this because I want to get this website done quickly, so I just want to input the roles and user mappings intially and have them stored in the database.  When the website is up, I will have to add users from time to time and possibly modify user/role mappings as w...

roles User.IsInRoles() and Roles.IsUserInRole()
Have some problems with roles    When I use  User.IsInRole("Admin") it retuns false even that it exists in the database and it appears when I run the code below. string[] test = Roles.GetRolesForUser();string hepp = "";foreach (string tst in test){    hepp += tst + "<br/>";} it returns Admin.with other words Roles.IsUserInRole("Admin") is true.Roles --> contains the roles but it is not transfered to User.   What am I doing wrong? Hur får jag User.IsInRole() till true? Can you post the code tha...

Membership and Roles
Hi all, Is there a way to allow the user choose a role from a selection you provide them with? e.g. I have 3 types of users: admin, contractor, and landlord. Of course I don't want them to be able to assign themselves admin role, so how would I proceed? (I'm using C# by the way) This is what I have so far. Please note "Roles...();" is where I am stuck: -within my aspx page i have: <asp:WizardStep ID="CreateUserWizardStep2" runat="server" Title="Contractor or Landlord?"> <asp:ListBox ID="ListBox1" runat=&q...

Cannot delete users from roles
I'm running DNN 2.1.2 , I cannot remove users from roles, even as admin and host. Has any seen this problem, solution?... Thanks...

Delete all users in a role
Is there a simple way to delete all users in a role from the data structure within the membership ui?  or do I have to do a loop? The hard way is to have all members in a role listed in a gridview with check box and check all button, then have a loop and have the checked users delete in a loop.  This takes alot of code, and is labor intensive.  I would like a button or sql statement or store proc for this.Thanks Scott I'd just do it in code like so: protected void Button1_Click(object sender, EventArgs e) { string[] users = Roles.GetUsersInRole("MyRole"...

how to delete users from roles?
  Hi all,   when i try to delete the role it says the following error,i created a role likt this : Roles.CreateRole("test");and i assigned some user like : Roles.AddUserToRole(companyEmployeeId, "test"); This role cannot be deleted because there are users present in it. please help me how to delete all the existing users in the role before to delete role. Thanks! You don't have to clear the members before you delete the role. Just pass a second argument of false to DeleteRole. This will cause the call to ignore the fact that there may be memb...

Login controls
HiI'm building a web app in visual studio 2005 and I'm setting up a 'create user' page for the admin part of the app. I'm creating a customised CreateUserWizard so that I can add a user to the asp.net membership list (in database on my server) and also add some info to one of my tables (user first name, faculty they work for etc).  I want to be able to let the admin user allocate roles (those already defined in my config) from a drop down list. I want to inculde this in my create user wizard, and have an 'update user' section where I can change their role the...

Web resources about - Delete Roles how affect Users in that roles - asp.net.security

Delete key - Wikipedia, the free encyclopedia
, known less ambiguously as forward delete ) discards the character ahead of the cursor 's position, moving all following characters one position ...

Facebook Fined $77K by Argentine Court for Failing to Delete Alleged Defamatory Groups
... mess in Argentina , as PanAm Post reported that a Rosario court ordered the social network to pay compensation of $77,000 for failing to delete ...

Facebook adds search history to Activity Log so users can delete queries
... in users’ Activity Logs. The feature will be rolled out to all users in the next few weeks. The feature allows for users to view and delete ...

Tweets MPs Delete (@deletedbyMPs) on Twitter
Sign in Sign up You are on Twitter Mobile because you are using an old version of Internet Explorer. Learn more here Tweets MPs Delete @ deletedbyMPs ...

Oren Jacob's answer to Pixar Animation Studios: Did Pixar accidentally delete Toy Story 2 during production ...
Oren Jacob's answer: Hi everyone, I'm the Oren Jacob in the video. Hopefully I can offer some first person color commentary about the video above ...

Tweeticide - Delete All of Your Twitter Tweets at Once! on the App Store on iTunes
Get Tweeticide - Delete All of Your Twitter Tweets at Once! on the App Store. See screenshots and ratings, and read customer reviews.

Delete, and I mean it! - Flickr - Photo Sharing!
I bought a new keyboard at work because I spilled cereal on the previous one and some of the keys stopped working. The new one has a giant delete ...

iOS 9 How-To: Quickly delete multiple images in Messages to free up space without losing your conversations ...
... Photos actually gets stored twice on the device: within Photos and within Messages. In this How-To article, I’m going to discuss how to delete ...

Viber now lets you attach files, delete messages and more
... and public chat forwarding in late September , the app keeps growing. In an update today, Nov. 24, Viber users can now attach files, delete ...

Anonymous aims to delete the Islamic State 'virus' from the web, and wants your help
... spread their ideals of terror among the young and impressionable. The aim of #OpISIS is to shut down these channels where possible, and "delete ...

Resources last updated: 12/6/2015 8:39:48 PM