title: Response.Redirect on page load not works
body: <p>I have two pages, a login page and a page1. The user cannot directly navigate to page1 as it contains following code for the pageload event. The user is redirected to the login page.</p>
  
  <pre><code>if (Session["role"] == null)
  {
      Response.Write("Redirect Not Working");
      Response.Redirect("loginpage.aspx");
  }
  </code></pre>
  
  <p>When the user clicks logout on pag1, he/she is redirected to the login page after setting <code>Session["role"]=null</code>. Now on the login page, if <strong>the user clicks on the browser back button</strong>, he/she is able to navigate to page1. <strong>Only in this case</strong> <code>Response.Redirect("loginpage.aspx");</code> in pageload event does not work. <strong>Why does it not work? How can I make it work, or how can I prevent the user from accessing page1 in this scenario?</strong></p>
  
  <p>I have been helpless and closed last time by asking it a different way <a href="https://stackoverflow.com/questions/13529025/code-to-detect-browser-back-button-click-for-anyall-browser">code to detect browser back button click for any(all) browser</a></p>
  
  <p><strong>Edit</strong> In response to answers: The code against the logout button is</p>
  
  <pre><code>protected void btnLogOut_Click(object sender, EventArgs e)
  {
      Session["role"] = null;
      Session.Abandon();
      Response.Redirect("login.aspx");
  }
  </code></pre>