0

hi..
i've review the latest logout and cannot back if BACK button is press..
anyone can help me in clearly how to code it?

4
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by crishjeny
0

new_SE Could you please be a bit more specific about what it is you're trying to do here? Your post is far from clear and therefor difficult to answer.

0

i'm trying to make a session end and the user cannot enter the system without login.. i had tried many ways but it still the same, user can enter the system after logout by hitting the back button.. for the login,i'm using session..
code for login

protected void Submit_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection("Server=(local); Database=test; user id=sa;  password=");
        SqlCommand cmd;
        string cmdstring = "SELECT [password] FROM [Customers] WHERE" + " [username]=@username and [password]=@password";
        
        cmd = new SqlCommand(cmdstring, conn);
        cmd.Parameters.Add("@username", SqlDbType.NVarChar, 50);
        cmd.Parameters["@username"].Value = txtUserName.Text;
        cmd.Parameters.Add("@password", SqlDbType.NVarChar, 50);
        cmd.Parameters["@password"].Value = txtPassword.Text;

        conn.Open();
        SqlDataReader reader;
        reader = cmd.ExecuteReader();
       
        if (reader.Read())
        {
            Session["username"] = txtUserName.Text;
            Response.Redirect("Default2.aspx");
            // FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, false);
        }
        else
        {
            Response.Write("Invalid Login!!");
        }
        reader.Close();
        conn.Close();
    }
}

for the logout, now i just have this:

Session["username"] = "null";
Session.Abandon();
Response.Redirect("Login2.aspx");

i dont what else should i put..

0

My friend i already suggested clear the cache of the page, do some googling man.

your problem is because your page once served from server gets cached at client End.

i.e the reason why after you hit the logout button, it will not call the page events.

but instead it will draws the page from the cache.

after clearing the cache, now when you hit the back button.

page will be requested from server and all the events will be executed and

user will get redirected to login page automatically if u r using the

formsAuthentication.

hope that helps.

http://www.aspdotnetfaq.com/Faq/How-to-disable-Client-Side-and-Proxy-Caching-of-ASP-NET-page.aspx

http://www.codeproject.com/KB/aspnet/NoCaching.aspx

0

Hi

You can refer following code for back and logout.

<a href="logout.jsp" target="_new" onclick="location.replace('browserClose.php');">Logout</a>

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.