//</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); }
//<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); }
//</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); }
//</snippet310> //<snippet311> private void LogoutUsingFormsAuthentication() { ClientFormsAuthenticationMembershipProvider authProvider = (ClientFormsAuthenticationMembershipProvider) System.Web.Security.Membership.Provider; authProvider.Logout(); }
protected void Page_Load(object sender, EventArgs e) { Session.RemoveAll(); Session.Abandon(); SessionHelper.SetSessionData("MenuUsuario", null); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(""), new string[0]); ClientFormsAuthenticationMembershipProvider authProvider = new ClientFormsAuthenticationMembershipProvider();// (ClientFormsAuthenticationMembershipProvider) FormsAuthentication.SignOut(); Response.Redirect("Login.aspx"); }
/// <summary> /// Log a user off the server. /// </summary> public void LogOut() { ClientFormsAuthenticationMembershipProvider authProvider = (ClientFormsAuthenticationMembershipProvider) System.Web.Security.Membership.Provider; try { authProvider.Logout(); } catch (WebException ex) { ConnectivityStatus.IsOffline = true; authProvider.Logout(); ConnectivityStatus.IsOffline = false; } }
//</snippet050> //<snippet070> private void logoutButton_Click(object sender, EventArgs e) { SaveSettings(); ClientFormsAuthenticationMembershipProvider authProvider = (ClientFormsAuthenticationMembershipProvider) System.Web.Security.Membership.Provider; try { authProvider.Logout(); } catch (WebException) { MessageBox.Show("Unable to access the authentication service." + Environment.NewLine + "Logging off locally only.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); ConnectivityStatus.IsOffline = true; authProvider.Logout(); ConnectivityStatus.IsOffline = false; } Application.Restart(); }