title: Detect browser refresh
body: <p>How can I find out if the user pressed F5 to refresh my page (Something like how SO implemented. If you refresh your page, the question counter is not increased). I have tested many code snippets mentioned in a dozen of tutorials, but none worked correctly.  </p>
  
  <p>To be more clear, suppose that i have an empty web form and would like to detect whether the user has pressed F5 in client-side (causing a refresh not submit) or not.  </p>
  
  <p>I can use session variables, but if the user navigates to another page of my site, and then comes back , I'd like to consider it as a new visit, not a refresh. so this is not a session-scope variable.  </p>
  
  <p>Thanks.  </p>
  
  <p><strong>Update:</strong> The only workaround I could find was to inherit my pages from a base page, override the load method like below:  </p>
  
  <pre><code>    public class PageBase : System.Web.UI.Page
  {
      protected override void OnLoad(EventArgs e)
      {
          base.OnLoad(e);
          this.Session["LastViewedPage"] = Request.RawUrl;
      }
  }  
  </code></pre>
  
  <p>and in every page if I was interested to know if this is a refresh:  </p>
  
  <pre><code>if (this.Session["LastViewedPage"].ToString() == Request.RawUrl)
  {
      // This is a refresh!
  }
  </code></pre>