I need to pass data to a variable in my master page each time a page is loaded.
I have a string[] of RequiredRoles that I set on each content page defining what roles are required to access that page.
On my master page, I have a method that takes this array, and checks to see if the current user is in one or more of those roles.
How would I go about managing this? I basically want each page to have a String[] RequiredRoles defined, and the master page will load this on each call and check to see if the users are in those roles.
To access members of a specific master page from a content page, you can create a strongly typed reference to the master page by creating a @ MasterType directive. The directive allows you to point to a specific master page. When the page creates its Master property, the property is typed to the referenced master page.
The master page establishes a layout and includes one or more ContentPlaceHolder controls for replaceable text and controls. The content page includes only the text and controls that are merged at run time with the master page's ContentPlaceHolder controls.
Typecast Page.Master to your master page so that you are doing something like:
((MyMasterPageType)Page.Master).Roles = "blah blah";
Add page directive to your child page:
<%@ MasterType VirtualPath="~/MasterPage.master" %>
Then add property to your master page:
public string Section { get; set; }
You can access this property like this:
Master.Section = "blog";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With