Click here to Skip to main content
12,625,607 members (34,463 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
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:
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

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 20-Feb-13 5:15am
Updated 20-Feb-13 5:16am
ProgramFOX189.3K
v2
Comments
ryanb31 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>
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Following Tip should help you out: Browser back button issue after logout[^]
  Permalink  
Comments
ProgramFOX 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!!!!!!!!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi,

Have a look at this Tip:
Browser back button issue after logout[^]
  Permalink  
Comments
Sandeep Mewara 20-Feb-13 10:40am
   
Ditto! My 5!
ProgramFOX 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161205.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100