Roles.Providers 속성

정의

ASP.NET 애플리케이션의 역할 공급자 컬렉션을 가져옵니다.

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

속성 값

RoleProviderCollection

ASP.NET 애플리케이션에 대해 구성된 역할 공급자가 포함된 RoleProviderCollection입니다.

예외

역할 관리가 사용되지 않는 경우

예제

다음 코드 예제에서는 애플리케이션 및 해당 유형이 사용 되는 공급자를 나열 합니다.

<%@ 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>

설명

Providers Web.config 파일에 추가 모든 공급자를 포함 하 여 애플리케이션에 사용 되는 모든 역할 공급자를 참조 하는 속성입니다. 애플리케이션에 대한 Web.config 파일의 roleManager 섹션 요소를 사용하여 providers 애플리케이션에 사용할 수 있는 역할 공급자를 제어할 수 있습니다.

다음 예제에서는 기존 공급자(예: Machine.config 파일에 지정된 공급자)를 제거하고 애플리케이션의 역할 공급자로 인스턴스를 SqlRoleProvider 추가하는 roleManager 섹션을 보여 줍니다.

<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>

이름으로 역할 공급자를 인덱싱하고 원하는 형식으로 캐스팅하여 컬렉션에서 Providers 공급자에 대한 강력한 형식의 참조를 얻을 수 있습니다.

애플리케이션에 대 한 기본 공급자에 대 한 참조를 가져올 수 있습니다는 Provider 속성입니다.

적용 대상

추가 정보