Set Masterpage from Global.asax in ASP.NET
<p>I want to set the Masterpage property in Global.asax.</p>

<p>This is what I have done but I get a <code>NullReferenceException</code> on the first line. Any ideas how to do this?</p>

<pre><code>protected void Application_PreSendRequestContent(Object sender, EventArgs e)
{
    System.Web.UI.Page page = System.Web.HttpContext.Current.Handler as System.Web.UI.Page;               

    if (Session["lang"] == "eng")
    {
        page.MasterPageFile = "SideMasterPageEng.master";
    }
}
</code></pre>
