private static void AddMasterPage(Page myPage)
        {
            if (string.IsNullOrEmpty(myPage.MasterPageFile)) return;

              var master = WebApplicationProxy.GetPageByLocation(myPage.MasterPageFile) as MasterPage;
              var masterField = typeof(Page).GetField("_master", BindingFlags.Instance | BindingFlags.NonPublic);
              masterField.SetValue(myPage, master);

              // Initialize the rest of the junk on page for the Master
              if (myPage.HasControls()) myPage.Controls.Clear();
              var contentTemplates = ((Page)myPage).get_ContentTemplateCollection();
              master.SetContentTemplates(contentTemplates);
              master.SetOwnerControl((Page)myPage);
              master.InitializeAsUserControl(myPage.Page);
              myPage.Controls.Add(master);
        }