title: Server.Transfer causing Session exception
body: <p>In my global I have the following code to handle when an error occurs</p>
  
  <pre><code>//[..] code goes here
    Server.Transfer("~/Error.aspx?ErrorID=" + errorId);
  </code></pre>
  
  <p>It used to be a <code>Response.Redirect</code> which worked perfectly except that it changed the url (which is why I want to use <code>Server.Transfer</code>)</p>
  
  <p>Unfortunately, now when it tries to load the Error page, it crashes on the Masterpage when it tries to refer to the <code>Session</code></p>
  
  <blockquote>
    <p>HttpException:<br>
    Session state can only be used when enableSessionState is set to true,
    either in a configuration file or in the Page directive. Please also
    make sure that System.Web.SessionStateModule or a custom session state
    module is included in the \\
    section in the application configuration.</p>
  </blockquote>
  
  <p>I do have enableSessionState in both my config and my page.</p>
  
  <p>I also found some links which suggest using Context.RewritePath - that just causes a blank page to load for me.</p>
  
  <p>Using <code>Response.Redirect</code> works perfectly and as expected, so I assume <code>Server.Transfer</code> is the issue here. What is it?</p>
  
  <p>EDIT Code:</p>
  
  <pre><code>protected void Application_Error(object sender, EventArgs e)
          {
  
              lock (_lockMe)
              {
                  Exception ex = Server.GetLastError();
  
                  if (ex != null)
                  {
                      if (ex.InnerException != null)
                          ex = ex.InnerException;
  
                      ErrorLoggingManager.AddError(ex, new MembershipData(), ...); //etc
                  }
  
                  Server.ClearError();
  
                     //Some other database code for cleaning up some stuff when an error happens
  
                  }
  
                  try
                  {
                      if (Response != null)
                      {
                          //Get the last error logged
                          MyDataContext db = new MyDataContext();
                          int errorId = db.LoggedErrors.OrderByDescending(le =&gt; le.ErrorId).Select(le =&gt; le.ErrorId).FirstOrDefault();
  
                          Server.Transfer("~/Error.aspx?ErrorID=" + errorId); 
                      }
                  }
                  catch (Exception)
                  {
                  }
              }
  </code></pre>