ClientFormsAuthenticationMembershipProvider Class

Definition

Enables forms authentication with client application services.

public ref class ClientFormsAuthenticationMembershipProvider : System::Web::Security::MembershipProvider
public class ClientFormsAuthenticationMembershipProvider : System.Web.Security.MembershipProvider
type ClientFormsAuthenticationMembershipProvider = class
    inherit MembershipProvider
Public Class ClientFormsAuthenticationMembershipProvider
Inherits MembershipProvider
Inheritance
ClientFormsAuthenticationMembershipProvider

Examples

The following example code demonstrates how to use this method to validate the user by using an IClientFormsAuthenticationCredentialsProvider implementation.

private bool ValidateUsingCredentialsProvider()
{
    bool isAuthorized = false;
    try
    {
        ClientFormsAuthenticationMembershipProvider authProvider =
            System.Web.Security.Membership.Provider as
            ClientFormsAuthenticationMembershipProvider;

        // Call ValidateUser with empty strings in order to display the 
        // login dialog box configured as a credentials provider.
        isAuthorized = authProvider.ValidateUser(String.Empty, String.Empty);
    }
    catch (System.Net.WebException)
    {
        MessageBox.Show("Unable to access the authentication service.",
            "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
    if (!isAuthorized)
    {
        MessageBox.Show("Unable to authenticate.", "Not logged in", 
            MessageBoxButtons.OK, MessageBoxIcon.Error);
        Application.Exit();
    }
    return isAuthorized;
}
Private Function ValidateUsingCredentialsProvider() As Boolean

    Dim isAuthorized As Boolean = False

    Try

        Dim authProvider As ClientFormsAuthenticationMembershipProvider = _
            CType(System.Web.Security.Membership.Provider,  _
            ClientFormsAuthenticationMembershipProvider)

        ' Call ValidateUser with empty strings in order to display the 
        ' login dialog box configured as a credentials provider.
        isAuthorized = authProvider.ValidateUser(String.Empty, String.Empty)

    Catch ex As System.Net.WebException

        MessageBox.Show("Unable to access the authentication service.", _
            "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)

    End Try

    If Not isAuthorized Then

        MessageBox.Show("Unable to authenticate.", "Not logged in", _
            MessageBoxButtons.OK, MessageBoxIcon.Error)
        Application.Exit()

    End If

    Return isAuthorized

End Function

Remarks

You can use client application services to validate users by using forms authentication. To enable forms authentication, you configure your application to use the ClientFormsAuthenticationMembershipProvider class.

After configuration, you can validate users by calling the static Membership.ValidateUser method, which internally calls the ClientFormsAuthenticationMembershipProvider.ValidateUser(String, String) method.

Forms authentication requires that the user specify their credentials through login controls provided by your application. You can retrieve the credentials and pass them to the Membership.ValidateUser method. You can also pass in empty strings or null to use a credentials provider. A credentials provider is an IClientFormsAuthenticationCredentialsProvider implementation specified in your application configuration file. You will typically implement the IClientFormsAuthenticationCredentialsProvider.GetCredentials method to display a login dialog box and return a populated ClientFormsAuthenticationCredentials object. Using a credentials provider enables you to share a single login dialog box among multiple applications.

The ClientFormsAuthenticationMembershipProvider.ValidateUser method authenticates users through the login service indicated by the ServiceUri property. The value of the ServiceUri property is typically retrieved from the application configuration file along with other configuration values.

If the user is successfully authenticated, the service provider sets the static Thread.CurrentPrincipal property to a new ClientRolePrincipal object that contains a new ClientFormsIdentity object that contains the user information. If a ClientRoleProvider is configured for your application, you can use the ClientRolePrincipal object to retrieve user role information from the roles service.

You can retrieve a reference to the current ClientFormsAuthenticationMembershipProvider instance through the static Membership.Provider property. You can use the membership provider reference to call the ClientFormsAuthenticationMembershipProvider.ValidateUser method directly. Additionally, you will need the membership provider reference to call the Logout method, which is not available in the MembershipProvider base class.

You cannot use the ClientFormsAuthenticationMembershipProvider class to create, delete, or modify membership information. To create, delete, or modify users, you must change the configuration of the login service on the server.

Constructors

ClientFormsAuthenticationMembershipProvider()

Initializes a new instance of the ClientFormsAuthenticationMembershipProvider class.

Properties

ApplicationName

This property is not used by this class.

Description

Gets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs).

(Inherited from ProviderBase)
EnablePasswordReset

This property is not used by this class.

EnablePasswordRetrieval

This property is not used by this class.

MaxInvalidPasswordAttempts

This property is not used by this class.

MinRequiredNonAlphanumericCharacters

This property is not used by this class.

MinRequiredPasswordLength

This property is not used by this class.

Name

Gets the friendly name used to refer to the provider during configuration.

(Inherited from ProviderBase)
PasswordAttemptWindow

This property is not used by this class.

PasswordFormat

This property is not used by this class.

PasswordStrengthRegularExpression

This property is not used by this class.

RequiresQuestionAndAnswer

This property is not used by this class.

RequiresUniqueEmail

This property is not used by this class.

ServiceUri

Gets or sets the URI of the authentication service.

Methods

ChangePassword(String, String, String)

This method is not used by this class.

ChangePasswordQuestionAndAnswer(String, String, String, String)

This method is not used by this class.

CreateUser(String, String, String, String, String, Boolean, Object, MembershipCreateStatus)

This method is not used by this class.

DecryptPassword(Byte[])

Decrypts an encrypted password.

(Inherited from MembershipProvider)
DeleteUser(String, Boolean)

This method is not used by this class.

EncryptPassword(Byte[])

Encrypts a password.

(Inherited from MembershipProvider)
EncryptPassword(Byte[], MembershipPasswordCompatibilityMode)

Encrypts the specified password using the specified password-compatibility mode.

(Inherited from MembershipProvider)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
FindUsersByEmail(String, Int32, Int32, Int32)

This method is not used by this class.

FindUsersByName(String, Int32, Int32, Int32)

This method is not used by this class.

GetAllUsers(Int32, Int32, Int32)

This method is not used by this class.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetNumberOfUsersOnline()

This method is not used by this class.

GetPassword(String, String)

This method is not used by this class.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetUser(Object, Boolean)

This method is not used by this class.

GetUser(String, Boolean)

This method is not used by this class.

GetUserNameByEmail(String)

This method is not used by this class.

Initialize(String, NameValueCollection)

Initializes the provider.

Logout()

Logs out the user.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnValidatingPassword(ValidatePasswordEventArgs)

Raises the ValidatingPassword event if an event handler has been defined.

(Inherited from MembershipProvider)
ResetPassword(String, String)

This method is not used by this class.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
UnlockUser(String)

This method is not used by this class.

UpdateUser(MembershipUser)

This method is not used by this class.

ValidateUser(String, String)

Authenticates a user by using the specified user name and password.

ValidateUser(String, String, Boolean)

Authenticates a user by using the specified user name and password, optionally storing a hash of the password in the local data cache.

ValidateUser(String, String, String)

Authenticates a user at the specified service URI by using the specified user name and password.

Events

UserValidated

Occurs when the user is validated.

ValidatingPassword

Occurs when a user is created, a password is changed, or a password is reset.

(Inherited from MembershipProvider)

Applies to

See also