Ejemplo n.º 1
0
        //</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);
        }
Ejemplo n.º 2
0
        //<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);
        }
Ejemplo n.º 3
0
        //</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);
        }
Ejemplo n.º 4
0
        //</snippet310>

        //<snippet311>
        private void LogoutUsingFormsAuthentication()
        {
            ClientFormsAuthenticationMembershipProvider authProvider =
                (ClientFormsAuthenticationMembershipProvider)
                System.Web.Security.Membership.Provider;

            authProvider.Logout();
        }
Ejemplo n.º 5
0
    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");
    }
Ejemplo n.º 6
0
        /// <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;
            }
        }
Ejemplo n.º 7
0
        //</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();
        }