This documentation is archived and is not being maintained.
RoleProvider.GetAllRoles Method
Visual Studio 2010
Gets a list of all the roles for the configured applicationName.
Assembly: System.Web.ApplicationServices (in System.Web.ApplicationServices.dll)
Return Value
Type: System.String[]A string array containing the names of all the roles stored in the data source for the configured applicationName.
GetAllRoles is called by the GetAllRoles method of the Roles class to retrieve a list of role names from the data source. Only the roles for the specified ApplicationName are retrieved.
If no roles exist for the configured applicationName, we recommend that your provider return a string array with no elements.
The following code example shows a sample implementation of the GetAllRoles method.
public override string[] GetAllRoles() { string tmpRoleNames = ""; OdbcConnection conn = new OdbcConnection(connectionString); OdbcCommand cmd = new OdbcCommand("SELECT Rolename FROM Roles " + " WHERE ApplicationName = ?", conn); cmd.Parameters.Add("@ApplicationName", OdbcType.VarChar, 255).Value = ApplicationName; OdbcDataReader reader = null; try { conn.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { tmpRoleNames += reader.GetString(0) + ","; } } catch (OdbcException) { // Handle exception. } finally { if (reader != null) { reader.Close(); } conn.Close(); } if (tmpRoleNames.Length > 0) { // Remove trailing comma. tmpRoleNames = tmpRoleNames.Substring(0, tmpRoleNames.Length - 1); return tmpRoleNames.Split(','); } return new string[0]; }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: