You need to use

SPSite site = null;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
site = new SPSite(Configuration.MyPmpUrl);
});
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
return web;

To open your site
Below is the code to change pagelayout of default page

            string url = SPContext.Current.Web.Url + "/" + TextBox1.Text;
            string pageName = "default.aspx";
            string layoutName = "DefaultLayout.aspx";

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {

                using (SPSite site = new SPSite(url))                
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        PublishingPage pubPage = null;
                        PageLayout pubLayout = null;
                        web.AllowUnsafeUpdates = true;

                        PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);

                        PublishingPageCollection pages = pubWeb.GetPublishingPages();

                        foreach (PublishingPage page in pages)
                        {
                            if (Equals(page.Name, pageName))
                            {
                                pubPage =  page;
                            }
                        }

                        PageLayout[] layouts = pubWeb.GetAvailablePageLayouts();

                        foreach (PageLayout layout in layouts)
                        {
                            if (Equals(layout.Name, layoutName))
                            {
                                pubLayout =  layout;
                            }
                        }

                        pubPage.CheckOut();

                        pubPage.Layout = pubLayout;
                        pubPage.Update();
                        pubPage.CheckIn("Page Modified For Layout Assimilation");
                        pubPage.ListItem.File.Publish(string.Empty);

                        if (pubPage.ListItem.ParentList.EnableModeration)
                        {
                            pubPage.ListItem.File.Approve(string.Empty);
                        }
                    }
                }

            });
Advertisements