Try Now
More in this section

Forums / General Discussions / validate when a page is viewed from the backend editor

validate when a page is viewed from the backend editor

2 posts, 0 answered
  1. Javier
    Javier avatar
    3 posts
    31 Jan 2013
    13 Feb 2013
    Link to this post
    I need to know if I'm visiting a paguina from Sitefinity editor
    to redirect only when it is accessed from the front end.

    paguina currently not editable because the redirect is working on the backend and I want to avoid that

  2. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    20 Oct 2016
    18 Feb 2013
    Link to this post

    To check if the current user visiting a page is in certain role create a user control and in Page_Load event check if the current user is in the editors role

    protected void Page_Load(object sender, EventArgs e)
               //get the current user
               var curretUserID = ClaimsManager.GetCurrentUserId();
               //check if the user is in role
               IsUserInRole(curretUserID, "Editors");
           public bool IsUserInRole(Guid userId, string roleName)
               bool isUserInRole = false;
               UserManager userManager = UserManager.GetManager();
               RoleManager roleManager = RoleManager.GetManager();
               var getUser = userManager.GetUser(userId);
               bool userExists = userManager.UserExists(getUser.UserName);
               bool roleExists = roleManager.RoleExists(roleName);
               if (userExists && roleExists)
                   //do actions if a user is in this role
                   isUserInRole = roleManager.IsUserInRole(userId, roleName);
               return isUserInRole;

    Stanislav Velikov
    the Telerik team
2 posts, 0 answered