Share via


FormsAuthenticationConfiguration.Credentials 屬性

定義

取得使用者名稱和密碼的 FormsAuthenticationCredentials 集合。

public:
 property System::Web::Configuration::FormsAuthenticationCredentials ^ Credentials { System::Web::Configuration::FormsAuthenticationCredentials ^ get(); };
[System.Configuration.ConfigurationProperty("credentials")]
public System.Web.Configuration.FormsAuthenticationCredentials Credentials { get; }
[<System.Configuration.ConfigurationProperty("credentials")>]
member this.Credentials : System.Web.Configuration.FormsAuthenticationCredentials
Public ReadOnly Property Credentials As FormsAuthenticationCredentials

屬性值

FormsAuthenticationCredentials 集合,此集合含有使用者名稱和密碼。

屬性

範例

下列程式碼範例示範如何存取 Credentials 屬性。 請參閱類別主題中的 FormsAuthenticationConfiguration 程式碼範例,以瞭解如何取得區段。

// Get the current Credentials.
FormsAuthenticationCredentials currentCredentials = 
    formsAuthentication.Credentials;

StringBuilder credentials = new StringBuilder();
// Get all the credentials.
for (System.Int32 i = 0; i < currentCredentials.Users.Count; i++)
{
    credentials.Append("Name: " + 
        currentCredentials.Users[i].Name + 
        " Password: " + 
        currentCredentials.Users[i].Password);
    credentials.Append(Environment.NewLine);
}
' Get the current Credentials.
  Dim currentCredentials _
  As FormsAuthenticationCredentials = _
  formsAuthentication.Credentials

Dim credentials As New StringBuilder()
' Get all the credentials.
Dim i As System.Int32
For i = 0 To currentCredentials.Users.Count - 1
      credentials.Append(("Name: " + _
      currentCredentials.Users(i).Name + _
      " Password: " + _
      currentCredentials.Users(i).Password))
   credentials.Append(Environment.NewLine)
  Next i

備註

屬性 Credentials 會取得表單型驗證期間要使用的使用者名稱和密碼。

注意

需要安全性時,您應該使用替代方式來儲存使用者名稱和密碼;例如,在資料庫存放區中。 如果您決定使用此集合,您應該使用提供的加密設備。

適用於