Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can I change a MasterPage at Runtime?
Message
From
27/04/2016 15:33:57
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Can I change a MasterPage at Runtime?
Environment versions
Environment:
C# 4.0
Miscellaneous
Thread ID:
01635492
Message ID:
01635492
Views:
55
Hi,

I've inherited an ASP.NET application and am trying to implement security the way they have done it which checks the user's rights (type) during login and then redirects the user to different pages based on different master pages. I now need to let two different types of users access the same page, but of course the Master Page won't work for this new user type.

Is there a way I can code the master page to be different depending on a session variable like this:
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["CanViewInvoiceHistory"] == "true")
            {
                this.Page.Master.MasterPageFile = "~/SiteSuper.master";
            }
        }
The code gives an error when I run the site:

Server Error in '/' Application.

Content controls have to be top-level controls in a content page or a nested master 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 have to be top-level controls in a content page or a nested master page that references a master page.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Next
Reply
Map
View

Click here to load this message in the networking platform