validate when a page is viewed from the backend editor
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
greeting
Hello,
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;
Greetings,
Stanislav Velikov
the Telerik team