FormsAuthenticationUserCollection.Add(FormsAuthenticationUser) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将 FormsAuthenticationUser 对象添加到集合中。
public:
void Add(System::Web::Configuration::FormsAuthenticationUser ^ user);
public void Add (System.Web.Configuration.FormsAuthenticationUser user);
member this.Add : System.Web.Configuration.FormsAuthenticationUser -> unit
Public Sub Add (user As FormsAuthenticationUser)
参数
要添加到集合的 FormsAuthenticationUser 对象。
例外
集合中已经存在该 FormsAuthenticationUser 对象,或此集合为只读。
示例
下面的代码示例说明如何使用 Add 方法。
// Using method Add.
// Define the SHA1 encrypted password.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
string password =
"5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8";
// Define the user name.
string userName = "newUser";
// Create the new user.
FormsAuthenticationUser currentUser =
new FormsAuthenticationUser(userName, password);
// Execute the Add method.
formsAuthenticationCredentials.Users.Add(currentUser);
// Update if not locked
if (!authenticationSection.SectionInformation.IsLocked)
{
configuration.Save();
}
' Using method Add.
' Define the SHA1 encrypted password.
' This example uses the SHA1 algorithm.
' Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
Dim password As String = _
"5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8"
' Define the user name.
Dim userName As String = "newUser"
' Create the new user.
Dim currentUser _
As New FormsAuthenticationUser(userName, password)
' Execute the Add method.
formsAuthenticationCredentials.Users.Add(currentUser)
' Update if not locked
If Not authenticationSection.SectionInformation.IsLocked Then
configuration.Save()
End If
注解
该集合不得包含 FormsAuthenticationUser 具有相同名称的对象。