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 获取在基于表单的身份验证期间要使用的用户名和密码。

注意

当需要安全性时,应使用其他方法来存储用户名和密码;例如,在数据库存储中。 如果决定使用此集合,则应使用提供的加密工具。

适用于