Click here to Skip to main content
15,895,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I have two webforms one is login page and another is home page. Whenever i clicks on logout button in "home page" it redirects to "login page" and if i clicks on "back" button in browser it redirects to home page which shouldn't be happened. Now my query is that whenever i would click "back" button in browser(after logging out from home page)it would redirect to login page rather than home page. Thanks........

LogIn Page Code:
C#
try
        {
            Session["ename"] = TextBox1.Text;
            cn.Open();
            SqlCommand SqlCmd = new SqlCommand("SELECT * FROM empregd WHERE ename='" + TextBox1.Text + "' AND password='" + TextBox2.Text + "'", cn);
            SqlDataAdapter SqlDa = new SqlDataAdapter(SqlCmd);
            SqlDataReader SqlDr = SqlCmd.ExecuteReader();
            if (SqlDr.Read())
            {
                Response.Redirect("http://localhost:49871/WebSite7/Default6.aspx");
            }
            SqlDr.Close();
            cn.Close();
            TextBox1.Text = "";
            TextBox2.Text = "";
        }
        catch (Exception ex)
        {
            throw ex;
        }

HomePage Code

C#
protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["ename"]== null)
            {
                Response.Redirect("http://localhost:49871/WebSite7/Default5.aspx");
            }
            Label2.Text = Session["ename"].ToString();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            Response.Redirect("http://localhost:49871/WebSite7/Default5.aspx");
            FormsAuthentication.SignOut();
            Session.Abandon();
            Session.Clear();
            Session["ename"] = null;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
Posted
Updated 20-Feb-13 4:16am
v2
Comments
ZurdoDev 20-Feb-13 10:19am    
What does your web.config's authentication look like?
Chiklu.Soumya 20-Feb-13 10:47am    
<configuration>

<system.web>
<compilation debug="false" targetframework="4.0">
</compilation></system.web>

</configuration>

Following Tip should help you out: Browser back button issue after logout[^]
 
Share this answer
 
Comments
Thomas Daniels 20-Feb-13 10:23am    
I was posting the same (but I can't delete my solution now, as you said in the Bugs & Suggestions forum).
Anyway, a 5!
Sandeep Mewara 20-Feb-13 10:40am    
Thats cool. No issues. Have 5. :)
Chiklu.Soumya 20-Feb-13 11:07am    
Thanks a lot!!!!!!!!
Hi,

Have a look at this Tip:
Browser back button issue after logout[^]
 
Share this answer
 
Comments
Sandeep Mewara 20-Feb-13 10:40am    
Ditto! My 5!
Thomas Daniels 20-Feb-13 10:52am    
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900