注意:此方法在 .NET Framework 2.0 版中是新增的。
获取已配置的
applicationName 的所有角色的列表。
命名空间:System.Web.Security
程序集:System.Web(在 system.web.dll 中)
Public MustOverride Function GetAllRoles As String()
Dim instance As RoleProvider
Dim returnValue As String()
returnValue = instance.GetAllRoles
public abstract string[] GetAllRoles ()
public:
virtual array<String^>^ GetAllRoles () abstract
public abstract String[] GetAllRoles ()
public abstract function GetAllRoles () : String[]
返回值
一个字符串数组,包含在数据源中存储的已配置的 applicationName 的所有角色的名称。
GetAllRoles 由 Roles 类的 GetAllRoles 方法调用,以从数据源检索角色名的列表。仅检索指定的 ApplicationName 的角色。
如果对于已配置的 applicationName 不存在任何角色,则建议提供程序返回不包含任何元素的字符串数组。
下面的代码示例演示 GetAllRoles 方法的示例实现。
Public Overrides Function GetAllRoles() As String()
Dim tmpRoleNames As String = ""
Dim conn As OdbcConnection = New OdbcConnection(connectionString)
Dim cmd As OdbcCommand = New OdbcCommand("SELECT Rolename FROM [" & rolesTable & "]" & _
" WHERE ApplicationName = ?", conn)
cmd.Parameters.Add("@ApplicationName", OdbcType.VarChar, 255).Value = ApplicationName
Dim reader As OdbcDataReader = Nothing
Try
conn.Open()
reader = cmd.ExecuteReader()
Do While reader.Read()
tmpRoleNames &= reader.GetString(0) & ","
Loop
Catch e As OdbcException
' Handle exception.
Finally
If Not reader Is Nothing Then reader.Close()
conn.Close()
End Try
If tmpRoleNames.Length > 0 Then
' Remove trailing comma.
tmpRoleNames = tmpRoleNames.Substring(0, tmpRoleNames.Length - 1)
Return tmpRoleNames.Split(CChar(","))
End If
Return New String() {}
End Function
public override string[] GetAllRoles()
{
string tmpRoleNames = "";
OdbcConnection conn = new OdbcConnection(connectionString);
OdbcCommand cmd = new OdbcCommand("SELECT Rolename FROM [" + rolesTable + "]" +
" 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 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
.NET Framework
受以下版本支持:2.0