title: How to Automatically Redirect if Session Expires? ASP.Net (From SessionTimeout.aspx to Timeout.aspx)
body: <p>I used Global.asax and this two codes give me error after session has timeout, like:
   'Response is not available in this context.' - if I used Response.Redirect
   'Object reference not set to an instance of an object.' - if I used HttpContext.Current.Response.Redirect</p>
  
  <p><strong>Global.asax</strong></p>
  
  <pre><code> protected void Session_End(object sender, EventArgs e)
          {
              //HttpContext.Current.Response.Redirect("timeout.aspx");
              Response.Redirect("~/timeout.aspx");
          }
  </code></pre>
  
  <p>and this is on my Web.Config</p>
  
  <p><strong>Web.Config</strong></p>
  
  <pre><code>&lt;configuration&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0" /&gt;
      &lt;customErrors defaultRedirect="../error_page/" mode="Off"/&gt;
      &lt;sessionState timeout="1" cookieless="false" mode="InProc" &gt;&lt;/sessionState&gt;
    &lt;/system.web&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p><strong>SessionTimeout.aspx.cs</strong></p>
  
  <pre><code> protected void Page_Load(object sender, EventArgs e)
          {
              Session["CustomSessionId"] = Guid.NewGuid();
          }
  </code></pre>
  
  <p>Do you guys have any solutions, suggestion especially snippets to make this work out? I am just an entry level programmer, not an advance one.</p>