FormsAuthenticationCredentials クラス
アセンブリ: System.Web (system.web.dll 内)
構文
解説FormsAuthenticationCredentials クラスを使用すると、構成ファイルの authentication セクション内の forms の credentials 要素にプログラムからアクセスして変更できます。この型は、FormsAuthenticationConfiguration 型、FormsAuthenticationUserCollection 型、FormsAuthenticationUser 型を含むグループの一部です。コレクション型以外はすべて、基になる構成タグに直接影響を与えます。
メモ |
|---|
| FormsAuthenticationCredentials は、MachineToApplication で定義される制限に従って構成ファイルの関連するセクションに情報を書き込むことができます。階層構造の許可されていないレベルで構成ファイルに書き込みを行おうとした場合、パーサーによってエラー メッセージが生成されます。ただし、このクラスを使用して、階層構造の任意のレベルに構成情報を読み込むことができます。安全性とスケーラビリティを高めるため、データベースなど、外部のリポジトリを使用して、ユーザーの資格情報を維持することをお勧めします。 |
使用例この例では、credentials セクションの複数の属性に対して、宣言によって値を指定する方法を示しています。これらの属性には、FormsAuthenticationCredentials クラスのメンバとしてもアクセスできます。
次の構成ファイルの例では、credentials セクションに対して、宣言によって値を指定する方法を示しています。
<credentials passwordFormat="SHA1"> <user name="aspnetuser1" password="5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8"/> <user name="aspnetuser2" password="E38AD214943DAAD1D64C102FAEC29DE4AFE9DA3D"/> </credentials>
メモ |
|---|
| credentials セクションを使用する場合は、「ASP.NET の認証」に説明されているガイドラインに従う必要があります。スケーラビリティとセキュリティを高めるため、外部のデータベースを使用して、ユーザーの資格情報を保管することをお勧めします。安全な ASP.NET アプリケーションを構築する方法の詳細については、Microsoft MSDN Web サイト (http://msdn.microsoft.com) で、「Securing Your ASP.NET Application」や「Building Secure ASP.NET Applications: Authentication, Authorization, and Secure Communication」を参照してください。 |
FormsAuthenticationCredentials クラスを使用する方法を次のコード例に示します。
' Get the Web application configuration. Dim configuration As System.Configuration.Configuration = _ WebConfigurationManager.OpenWebConfiguration( _ "/aspnetTest") ' Get the authentication section. Dim authenticationSection _ As AuthenticationSection = _ CType(configuration.GetSection( _ "system.web/authentication"), AuthenticationSection) ' Get the forms credentials collection . Dim formsAuthenticationCredentials _ As FormsAuthenticationCredentials = _ authenticationSection.Forms.Credentials
// Get the Web application configuration. System.Configuration.Configuration configuration = WebConfigurationManager.OpenWebConfiguration("/aspnetTest"); // Get the authentication section. AuthenticationSection authenticationSection = (AuthenticationSection)configuration.GetSection( "system.web/authentication"); // Get the forms credentials collection . FormsAuthenticationCredentials formsAuthenticationCredentials = authenticationSection.Forms.Credentials;
継承階層System.Configuration.ConfigurationElement
System.Web.Configuration.FormsAuthenticationCredentials
スレッド セーフ
プラットフォーム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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照- FormsAuthenticationCredentials クラスのページへのリンク
.gif)