ASP.NET master page error
<p>The master page is getting called twice. Once after the full page is rendered. At this time isPostback value is false and SESSION is null. </p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        //SOME CODE

        try
        {
            strUserId = Session[USERID].ToString();
        }
        catch
        {
            Response.Redirect("error.aspx");
        }
    }
}
</code></pre>

<p>For the first page load of master page (before rendering of page) everything is fine. After rendering again page_load of master page is called. This time accessing SESSION is giving an exception:</p>

<blockquote>
  <p>HttpException (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 <code>&lt;configuration&gt;\&lt;system.web&gt;\&lt;httpModules&gt;</code> section in the application configuration.). </p>
</blockquote>

<p>I dont have any problem if page_load is getting called twice or thrice. I just dont want to access SESSION on second page load.</p>

<p><strong>EDIT 2</strong></p>

<p>The second master page load is happening because of this code which i've overseen earlier (present Global.asax file)</p>

<pre><code> void Application_Error(object sender, EventArgs e) 
    {         
       Server.Transfer("~/ErrorMessage.aspx");
    }
</code></pre>

<p>The ErrorMessage.aspx page is the child page of master page :(</p>

<p>But still the answered question is why is the Application_Error() being generated even on successful rendering of pages? I tried to keep a break point at Application_Error() and event args is empty every time.</p>
