More in this section

Forums / Developing with Sitefinity / User permissions

User permissions

2 posts, 0 answered
  1. Anton Mernov
    Anton Mernov avatar
    110 posts
    Registered:
    03 Dec 2008
    09 Feb 2009
    Link to this post
    Hi guys,

    How I can get and set user permissions programmatically? e.g. then user save some generic content...

    Thanks,
    Anton.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    10 Feb 2009
    Link to this post
    Hello Anton,

    Permissions in Sitefintiy are based on roles of users. Every role has permissions over a given module.
    Here is the approach you could use to get or set some permissions programatically.

    protected void Button1_Click(object sender, EventArgs e) 
        { 
            // will return true if the permissions are set for forums module 
            Response.Write(CheckModulePermissions("forums", CrudRights.View | CrudRights.Delete)); 
        } 
         
     
        private bool CheckModulePermissions(string moduleName, int rights) 
        { 
            ISecuredModule module = ModuleManager.WebModules[moduleName] as ISecuredModule; 
            if (module != null
            {    
                // here we set the permissions to our role called ForumUsers 
                ISecured permissions = module.SecurityRoot; 
                permissions.SetPermissions(CrudRights.View, CrudRights.Delete, "ForumUsers"); 
            } 
            return true
        } 


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
2 posts, 0 answered