When using webforms the appropriate place to assign master pages to a page dynamically seems to be the pages PreInit event:
this.Master.MasterPageFile = "~/leaf.Master"
If nessasary, master pages in a hierarchy of nested master pages may be set here too:
this.Master.MasterPageFile = "~/leaf.Master"
this.Master.Master.MasterPageFile = "~/root.Master"
Using the MVC framework you can set a single master page name dynamically using the controllers View method by passing the masterName, but how do you set other master pages higher up in the hierarchy?
Update
Sorry I was not clear.
By hierarchy i mean a chain of nested master pages, so how can i set the very top master page in a chain of nested master pages?
For example we have a set up such that different customer types have different master pages and nested within this master page is an additional master page for specific user roles. We need to dynamically set the root customer master as well as the role master.