How do I get the roles for an authenticated logged in extranet user in sitecore 6.4? I'm trying to check the roles to restrict access.
The Sitecore.Context.User.Roles is coming back with default\Anonynous not extranet\WebsiteUser.
UPDATE: When checking the roles directly after login all appears fine. However it's when I check the roles from within a httphandler that the Sitecore.Context.User.Roles is lost and defaults to default\Anonynous.
Create extranet user code:
using (new SecurityStateSwitcher(SecurityState.Disabled))
{
var domainUsername = Context.Domain.GetFullName(user.Email);
Sitecore.Security.Accounts.User sitecoreUser = Sitecore.Security.Accounts.User.Create(domainUsername, user.Password);
Database dbCore = Factory.GetDatabase("core");
Item profileItem = dbCore.GetItem(CustomUserProfilePath);
List<Role> roles = Sitecore.Context.Domain.GetRoles().Where(role => role.Name == "extranet\WebsiteUser").ToList();
if (roles.Any())
{
sitecoreUser.Roles.Add(roles.First());
}
sitecoreUser.Profile.ProfileItemId = profileItem.ID.ToString();
sitecoreUser.Profile.FullName = string.Format("{0} {1}", user.FirstName, user.LastName);
sitecoreUser.Profile.Email = user.Email;
sitecoreUser.Profile.Comment = "Created by the register system";
sitecoreUser.Profile.Save();
}