I am attempting to make a website that can be edited online by the owner. One of the settings is layout and I want to do this through masterpages. The result of their choice is stored in an xml file called layout.xml.
I added this bit of code to the content page:
public class DynamicPage : System.Web.UI.Page
{
protected override void OnPreInit(EventArgs e)
{
SiteTools st = new SiteTools();
string layout = st.getLayout(Request);
if (!layout.Equals(string.Empty))
{
base.MasterPageFile = layout;
}
base.OnPreInit(e);
}
}
here is the getLayout portion
public string getLayout(HttpRequest Request)
{
getPath(Request);
try
{
xdoc.Load(_path + "\\config.xml");
XmlNodeList layout = xdoc.GetElementsByTagName("layout");
if (layout.Count > 0)
{
return layout[0].ChildNodes[0].InnerText;
}
return "";
}
catch (Exception ex)
{
if (ex.Message.Contains("Could not find a part of the path"))
{
return "XmlCreated";
}
return "Error: " + ex.Message;
}
}
here is the layout content of config.xml
<theme><![CDATA[coffee]]></theme>
<layout><![CDATA[~/masterpageb.master]]></layout>
when I try to access the edited page I get this error:
Content controls are allowed only in content page that references a
master page.
Description:
An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and
where it originated in the code.
Exception Details:
System.Web.HttpException: Content controls are allowed only in content page
that references a master page.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
|
Stack Trace:
[HttpException (0x80004005): Content controls are allowed only in content page that references a master page.] System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) +1116 System.Web.UI.Page.get_Master() +49 System.Web.UI.Page.ApplyMasterPage() +17 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1368
|
Any ideas?
Thanks,
Bob