How to use a common homepage for different roles?

I want to use common master-pagefor different roles, I just want to set different themes and menu items according to roles, can someone direct me on how I can use in my membership code on the same main page?

For my current code, I downloaded the membership code from a set of code that sets up different master pages for different roles, but I see when I need to make some page common to all roles that should be accessible according to the roles, I have to make the page of the page in each roles folder and set it in the main menu of the page in accordance with the role, so I want to use a common main page for everyone ....

+3
source share
1 answer

You can change the main page programmatically during the method OnPreInit:

protected override void OnPreInit(EventArgs e)
{
    base.OnPreInit(e);    

    if (Roles.IsUserInRole("Admins"))
    {         
        Page.MasterPageFile = "AdminDefault.master";
        return;
    }

    Pages.MasterPageFile = "Default.master";
}

If this function will be used by several or more pages, I would think about putting it in a base class that pages can inherit from.

+1
source

All Articles