Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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 4:15am
Edited 20-Feb-13 4:16am
ProgramFOX118.9K
v2
Comments
ryanb31 at 20-Feb-13 10:19am
   
What does your web.config's authentication look like?
Chiklu.Soumya at 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 at 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 at 20-Feb-13 10:40am
   
Thats cool. No issues. Have 5. :)
Chiklu.Soumya at 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 at 20-Feb-13 10:40am
   
Ditto! My 5!
ProgramFOX at 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
0 OriginalGriff 205
1 Sergey Alexandrovich Kryukov 185
2 jlopez788 144
3 Rob Philpott 100
4 Prakriti Goyal 97
0 OriginalGriff 6,837
1 Sergey Alexandrovich Kryukov 5,559
2 Maciej Los 3,479
3 Peter Leow 3,323
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2014
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