Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Session Problem.. (Back Button)

Session Problem.. (Back Button)

Scheduled Pinned Locked Moved ASP.NET
help
4 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kunal P
    wrote on last edited by
    #1

    hi i wanted to implement sessions in my application... i wrote the following code on the login page if (dread.Read()) { Session["user"] = uname.Text; Response.Redirect("MainP.aspx"); } then on the page load event of the following pages i wrote this code..(used master pages.though) if (!IsPostBack) { if (Session["user"] != null) { Label1.Text = Session["user"].ToString() + "!!"; //Label1.Text = Session["user"].ToString(); Response.Cache.SetExpires(DateTime.Now.AddSeconds(0)); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetValidUntilExpires(true); } else { Response.Redirect("login.aspx"); string uname = (string)(Session["User"]); } } Now the problem is that, if i dont login, no page will open, if i type the URL, but afted logout, on BACK BUTTON press of the web browser, the page opens, instead of getting redirected to login page. any ideas.. then i created a LOGOUT LInk Button, and wrote the following code... protected void LinkButton1_Click(object sender, EventArgs e) { Session.Abandon(); Session.Clear(); Session["user"] = null; Response.Redirect("login.aspx"); }

    Kunal

    _ V 2 Replies Last reply
    0
    • K Kunal P

      hi i wanted to implement sessions in my application... i wrote the following code on the login page if (dread.Read()) { Session["user"] = uname.Text; Response.Redirect("MainP.aspx"); } then on the page load event of the following pages i wrote this code..(used master pages.though) if (!IsPostBack) { if (Session["user"] != null) { Label1.Text = Session["user"].ToString() + "!!"; //Label1.Text = Session["user"].ToString(); Response.Cache.SetExpires(DateTime.Now.AddSeconds(0)); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetValidUntilExpires(true); } else { Response.Redirect("login.aspx"); string uname = (string)(Session["User"]); } } Now the problem is that, if i dont login, no page will open, if i type the URL, but afted logout, on BACK BUTTON press of the web browser, the page opens, instead of getting redirected to login page. any ideas.. then i created a LOGOUT LInk Button, and wrote the following code... protected void LinkButton1_Click(object sender, EventArgs e) { Session.Abandon(); Session.Clear(); Session["user"] = null; Response.Redirect("login.aspx"); }

      Kunal

      _ Offline
      _ Offline
      _mubashir
      wrote on last edited by
      #2

      Hi, Put the following piece of code on every page, outside of postback check if (Session["user"] == null){ Response.Redirect("login.aspx"); string uname = (string)(Session["User"]); } Mubashir

      Every job is a self portrait of the person who did it.

      K 1 Reply Last reply
      0
      • K Kunal P

        hi i wanted to implement sessions in my application... i wrote the following code on the login page if (dread.Read()) { Session["user"] = uname.Text; Response.Redirect("MainP.aspx"); } then on the page load event of the following pages i wrote this code..(used master pages.though) if (!IsPostBack) { if (Session["user"] != null) { Label1.Text = Session["user"].ToString() + "!!"; //Label1.Text = Session["user"].ToString(); Response.Cache.SetExpires(DateTime.Now.AddSeconds(0)); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetValidUntilExpires(true); } else { Response.Redirect("login.aspx"); string uname = (string)(Session["User"]); } } Now the problem is that, if i dont login, no page will open, if i type the URL, but afted logout, on BACK BUTTON press of the web browser, the page opens, instead of getting redirected to login page. any ideas.. then i created a LOGOUT LInk Button, and wrote the following code... protected void LinkButton1_Click(object sender, EventArgs e) { Session.Abandon(); Session.Clear(); Session["user"] = null; Response.Redirect("login.aspx"); }

        Kunal

        V Offline
        V Offline
        Venkatesh Mookkan
        wrote on last edited by
        #3

        Kunal P wrote:

        Response.Cache.SetExpires(DateTime.Now.AddSeconds(0)); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetValidUntilExpires(true);

        Move the above code to the beginning of the Page_Load Event.

        Regards, Venkatesh Mookkan. Software Engineer, India My: Website | Yahoo Group

        1 Reply Last reply
        0
        • _ _mubashir

          Hi, Put the following piece of code on every page, outside of postback check if (Session["user"] == null){ Response.Redirect("login.aspx"); string uname = (string)(Session["User"]); } Mubashir

          Every job is a self portrait of the person who did it.

          K Offline
          K Offline
          Kunal P
          wrote on last edited by
          #4

          not working.. that back button still gets me to the page.. is there a problem with the logout link button code..??

          Kunal

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups