Export (0) Print
Expand All

FormsAuthenticationUserCollection.Add Method

Adds a FormsAuthenticationUser object to the collection.

Namespace:  System.Web.Configuration
Assembly:  System.Web (in System.Web.dll)

public void Add(
	FormsAuthenticationUser user
)

Parameters

user
Type: System.Web.Configuration.FormsAuthenticationUser

The FormsAuthenticationUser object to add to the collection.

ExceptionCondition
ConfigurationException

The FormsAuthenticationUser object already exists in the collection, or the collection is read-only.

The collection must not contain a FormsAuthenticationUser object with the same name.

The following code example shows how to use the Add method.

            // Using method Add. 

            // Define the SHA1 encrypted password. 
            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();
            }

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0
Show:
© 2015 Microsoft