Roles.Providers Propriedade

Definição

Obtém uma coleção de provedores de função para o aplicativo ASP.NET.Gets a collection of the role providers for the ASP.NET application.

public:
 static property System::Web::Security::RoleProviderCollection ^ Providers { System::Web::Security::RoleProviderCollection ^ get(); };
public static System.Web.Security.RoleProviderCollection Providers { get; }
member this.Providers : System.Web.Security.RoleProviderCollection
Public Shared ReadOnly Property Providers As RoleProviderCollection

Valor da propriedade

RoleProviderCollection

Um RoleProviderCollection que contém os provedores de função configurados para o aplicativo ASP.NET.A RoleProviderCollection that contains the role providers configured for the ASP.NET application.

Exceções

O gerenciamento de função não está habilitado.Role management is not enabled.

Exemplos

O exemplo de código a seguir lista os provedores habilitados para um aplicativo e seus respectivos tipos.The following code example lists the providers enabled for an application and their respective types.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Configuration.Provider" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>List Enabled Providers</title>
</head>
<body>

<%
foreach (RoleProvider p in Roles.Providers)
  Response.Write(p.Name + ", " + p.GetType() + "<br />");
%>

</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Configuration.Provider" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>List Enabled Providers</title>
</head>
<body>

<%
For Each p As RoleProvider In Roles.Providers
  Response.Write(p.Name & ", " & p.GetType().ToString() & "<br />")
Next
%>

</body>
</html>

Comentários

A Providers propriedade faz referência a todos os provedores de função habilitados para um aplicativo, incluindo todos os provedores adicionados no arquivo de Web.config.The Providers property references all the role providers enabled for an application, including any providers added in the Web.config file. Você pode controlar quais provedores de função estão disponíveis para um aplicativo usando o providers elemento da seção roleManager no arquivo de Web.config para seu aplicativo.You can control which role providers are available for an application by using the providers element of the roleManager section in the Web.config file for your application.

O exemplo a seguir mostra uma seção roleManager que remove todos os provedores existentes (como aqueles especificados no arquivo Machine.config) e adiciona uma SqlRoleProvider instância como o provedor de função para o aplicativo.The following example shows a roleManager section that removes any existing providers (such as those specified in the Machine.config file) and adds a SqlRoleProvider instance as the role provider for the application.

<configuration>
  <connectionStrings>
    <add name="SqlServices" connectionString="Data Source=MySqlServer;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />
  </connectionStrings>

  <system.web>
    <roleManager defaultProvider="SqlProvider"
      enabled="true"
      cacheRolesInCookie="true"
      cookieName=".ASPROLES"
      cookieTimeout="30"
      cookiePath="/"
      cookieRequireSSL="false"
      cookieSlidingExpiration="true"
      cookieProtection="Encrypted">

      <providers>
        <clear/>
        <add
          name="SqlProvider"
          type="System.Web.Security.SqlRoleProvider"
          connectionStringName="SqlServices"
          applicationName="MyApplication" />
         </providers>

    </roleManager>
  </system.web>
</configuration>

Você pode obter uma referência fortemente tipada a um provedor da Providers coleção indexando o provedor de função por nome e convertendo-o como o tipo desejado.You can obtain a strongly typed reference to a provider from the Providers collection by indexing the role provider by name and casting it as the desired type.

Você pode obter uma referência ao provedor padrão para um aplicativo usando a Provider propriedade.You can obtain a reference to the default provider for an application using the Provider property.

Aplica-se a