DeleteRole Method (String, Boolean)
Collapse the table of content
Expand the table of content

Roles.DeleteRole Method (String, Boolean)


Removes a role from the data source.

Namespace:   System.Web.Security
Assembly:  System.Web (in System.Web.dll)

public static bool DeleteRole(
	string roleName,
	bool throwOnPopulatedRole


Type: System.String

The name of the role to delete.

Type: System.Boolean

If true, throws an exception if roleName has one or more members.

Return Value

Type: System.Boolean

true if roleName was deleted from the data source; otherwise; false.

Exception Condition

roleName is null.


roleName is an empty string.


roleName has one or more members and throwOnPopulatedRole is true.


Role management is not enabled.

The DeleteRole method removes a role name from the data source. DeleteRole calls the DeleteRole method of the default role provider to remove the specified role from the data source.

If throwOnPopulatedRole is true, then an exception will be thrown and the role will not be deleted if the role identified by the roleName parameter has one or more members. If throwOnPopulatedRole is false, then the role will be deleted whether it is empty or not.

Legacy Code Example

The following code example deletes a role from the data source. For an example of a Web.config file that enables role management, see Roles.

Code snippet is not found. Confirm that the code snippet name 'System.Web.Security.SqlRoleProvider' is correct.

.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft