AI OnAI Off
Try this-
System.Web.HttpContext.Current.User.Identity.Name
or if you are using Membership then you can use - Membership.GetUser.it will contain userid.
For the roles this should work: EPiServer.Security.PrincipalInfo.CurrentPrincipal.IsInRole("WebAdmins")
Hello,
Am trying to fetch the username and role for website and returns null for current user. I want to check if logged in user belong to role WebAdmins or Administrator so that they can have access to one of the functionality which others can't see. I added like this:
bool currentUserIsWebAdmins = System.Web.Security.Roles.IsUserInRole("WebAdmins");
bool currentUserIsAdministrator = System.Web.Security.Roles.IsUserInRole("Administrators");
if (currentUserIsWebAdmins && currentUserIsAdministrator)
{
// code goes here
}
string currentUser = EPiServer.Security.PrincipalInfo.CurrentPrincipal.Identity.Name; when I checked the currentuser it's null.
Is this correct way to fetch currentusername for a website and am I missing any configuration?
Please help.