//<snippet307> private bool ValidateUsingLoginControls() { bool isAuthorized = false; try { ClientFormsAuthenticationMembershipProvider authProvider = System.Web.Security.Membership.Provider as ClientFormsAuthenticationMembershipProvider; // Call ValidateUser with credentials retrieved from login controls. isAuthorized = authProvider.ValidateUser(usernameTextBox.Text, passwordTextBox.Text, rememberMeCheckBox.Checked); } 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); }
//</snippet307> //<snippet308> private bool ValidateUsingServiceUri(String serviceUri) { bool isAuthorized = false; try { // Call the static overload of ValidateUser. Specify credentials // retrieved from login controls and the service location. isAuthorized = ClientFormsAuthenticationMembershipProvider.ValidateUser( usernameTextBox.Text, passwordTextBox.Text, serviceUri); } 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); }
//</snippet305> //<snippet306> 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); }