Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hueman domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/CloudIngenium.com/htdocs/wp-includes/functions.php on line 6114
What is the best way to redirect a user to the login page? – Knowledge eXchange

What is the best way to redirect a user to the login page?

If I wanted to redirect the user to the login page for some reason (either they are not logged in or we sign them out automatically) what would be the best way to redirect them there? I can manually do a Redirect but I am sure there is probably a more integrated method to do this through ASP.Net membership or something. Also, the Web.config already has the login page, so from a maintainability perspective I don’t want to keep the login URL in many places. Any thoughts?


One of the most consistant methods would be the following:

        /// <summary>

        /// Check if current user is valid, else redirect to the login page

        /// </summary>

        private void CheckUserIsAuthenticated()

        {

            MembershipUser user = Membership.GetUser();

            if (user == null)

                FormsAuthentication.RedirectToLoginPage();

            else

            {

                if (String.IsNullOrEmpty(user.ToString()))

                {

                    FormsAuthentication.RedirectToLoginPage();

                }

            }

        }

By using the RedirectToLoginPage you use the settings in FormsAuthentication (obtained from the Web.Config). Just keep in mind that the current thread continues to execute so any code after the “FormsAuthentication.RedirectToLoginPage();” will in fact execute.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.