Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6868391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:25:43+00:00 2026-05-27T03:25:43+00:00

I have created a simple login page for asp.net which takes in user name

  • 0

I have created a simple login page for asp.net which takes in user name and password in text boxes and compare it with the one I have stored in database and redirects only if it is same as stored in database.

But what is happening is that when I login and then go back by pressing back button, then again pressing forward button of browser,it is still redirecting users.

So can anyone help with this issue as to as once logged out,it should redirect only after entering credentials and not by pressing forward button of the browser.

protected void LoginButton_Click(object sender, EventArgs e)
    {
        int results = 0;
        if (txtUsername.Text != "" && txtPassword.Text != "")
        {
            results = Validate_Login(txtUsername.Text, txtPassword.Text);
        }
        else
        {
            lblMessage.Text = "Please make sure that the username and the password is Correct";
        }
        if (results == 1)
        {
            if (txtUsername.Text.Equals("admin"))
            {
                Response.Redirect("~/ConfigurationPage.aspx");
            }
            else
            {
                Response.Redirect("");
            }
        }
        else
        {
            lblMessage.Text = "Invalid Login";
            lblMessage.ForeColor = System.Drawing.Color.Red;
        }
    }

    public int Validate_Login(String username, String password)
    {
        var conString = ConfigurationManager.ConnectionStrings["ConnectionString"];
        string strConnString = conString.ConnectionString;
        int results = 0;

        using (SqlCommand cmdselect = new SqlCommand
                                   {
                                       CommandType = CommandType.StoredProcedure,
                                       CommandText = "[dbo].[prcLoginv]"
                                   })
        {

            cmdselect.Parameters.Add("@Username", SqlDbType.VarChar, 50).Value = username;
            cmdselect.Parameters.Add("@UPassword", SqlDbType.VarChar, 50).Value = password;
            cmdselect.Parameters.Add("@OutRes", SqlDbType.Int, 4);

            cmdselect.Parameters["@OutRes"].Direction = ParameterDirection.Output;



            try
            {
                if (connection == null)
                {
                    connection = new SqlConnection(strConnString);
                    connection.Open();
                    cmdselect.Connection = connection;
                    cmdselect.ExecuteNonQuery();
                    results = (int) cmdselect.Parameters["@OutRes"].Value;
                }
                else if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                    cmdselect.ExecuteNonQuery();
                    results = (int) cmdselect.Parameters["@OutRes"].Value;
                }

            }
            catch (SqlException ex)
            {
                lblMessage.Text = ex.Message;
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }
        return results;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:25:43+00:00Added an answer on May 27, 2026 at 3:25 am

    I have had this scenario in the past. In reality, nothing happens in the server when you press the back and forward button. So what I usually do is to also check on the client (I check the Session variables in the client):

    <script>
        var isLogged = '<%=Session["Logged"] %>';
        if (isLogged != 'True') {
            window.location.href = 'About.aspx';
        }
    </script>
    

    That was just a simple example. Please notice though, that it does not matter if the person can click the back or forward button, as soon as a postback happens they will be taken out of that page.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a simple Asp.Net custom control which automatically combines all the correct
I have created a simple login page which is based on the sessions. session_start();
I have a simple authorization page which intends the user to type login and
I am very new to flex, i have created a simple login page in
I created this simple login page. It's supposed to display in the label text
I have created a simple wcf service which used the WCF Service Library template.
i have created a simple public ref class in the vc++ project, which is
Let's say I have a simple Login servlet that checks the passed name and
In Sitecore 6, I have created a sublayout that has an asp:login control. For
I am Working on simple login application in which user is first shown login

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.