Set Property Value on Master Page from Content Page

WedTM picture WedTM · Jul 2, 2009 · Viewed 30.4k times · Source

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.

Answer

HasanG picture HasanG · Jul 24, 2010

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";