Checking user permissions

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

Getting current user's name

 

[C#]

 

string currentUserName = CMS.CMSHelper.CMSContext.CurrentUser.UserName;

 

Checking if user is authenticated

 

[C#]

 

bool isAuthenticated = HttpContext.Current.User.Identity.IsAuthenticated;

 

Checking if user is member of a role

 

[C#]

 

if (CMS.CMSHelper.CMSContext.CurrentUser.IsInRole("CMSEditor", CMS.CMSHelper.CMSContext.CurrentSiteName))

{

  //the current user is member of the CMSEditor role

}

 

Checking if a permission for a document is granted to a user

 

[C#]

 

if (CMS.CMSHelper.CMSContext.CurrentUser.IsAuthorizedPerTreeNode(nodeId, CMS.TreeEngine.NodePermissionsEnum.Read) ==

     CMS.TreeEngine.AuthorizationResultEnum.Allowed)

{

  // the current user is authorized to read the document              

}

 

Checking if a permission for a module (resource) is granted to a user

 

[C#]

 

if (CMS.CMSHelper.CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Forums", "Modify"))

{

  // the "Modify" permission in the "CMS.Forums" module in the current website is granted to the current user

}

 

Checking if a permission for a document type or custom table (class name) is granted to a user

 

[C#]

 

if (CMS.CMSHelper.CMSContext.CurrentUser.IsAuthorizedPerClassName("CMS.File", "Delete"))

{

  // the "Delete" permission for all documents of type "CMS.File" in the current website is granted to the current user

}

 

Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?checking_user_permissions.htm