Roles.Providers プロパティ
アセンブリ: System.Web (system.web.dll 内)

ASP.NET アプリケーション用に構成されたロール プロバイダを含む RoleProviderCollection。


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 コレクションからプロバイダへの厳密に型指定された参照を取得できます。

アプリケーションに対して有効なプロバイダとそれらの種類をリストするコードの例を次に示します。
<%@ Page Language="VB" %> <%@ Import Namespace="System.Web.Security" %> <%@ Import Namespace="System.Configuration.Provider" %> <html> <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>
<%@ Page Language="C#" %> <%@ Import Namespace="System.Web.Security" %> <%@ Import Namespace="System.Configuration.Provider" %> <html> <head> <title>List Enabled Providers</title> </head> <body> <% foreach (RoleProvider p in Roles.Providers) Response.Write(p.Name + ", " + p.GetType() + "<BR>"); %> </body> </html>

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Roles.Providers プロパティのページへのリンク