Hi Folks,
I'm having a little trouble with programmatically adding User Roles, and being able to get a decent handle on the current User Roles after adding.
I'm able to add a Role to a User just fine, but it's not until the second page refresh that my "output" textbox has the expiryDate as I expect.
In stepping through the following code in debug; after adding the Role - my UserInfo (cUser in this case) - is not that in that role, until I refresh the page again.
Running DNN 7.3
try
{
if (HttpContext.Current.Session["trialUser"] != null)
sTrialStatus = HttpContext.Current.Session["trialUser"].ToString();
if (sTrialStatus == "Trial")
{
bTrialUser = true;
}
else
{
bTrialUser = false;
}
if (Request.IsAuthenticated && !_currentUser.IsInRole("Trial") && bTrialUser == true)
{
RoleController ctrRoles = new RoleController();
RoleInfo oCurrentRole = ctrRoles.GetRoleByName(this.PortalId, "Trial");
uRole = ctrRoles.GetUserRole(this.PortalId, _currentUser.UserID, oCurrentRole.RoleID);
ctrRoles.AddUserRole(this.PortalId, _currentUser.UserID, oCurrentRole.RoleID, System.DateTime.Now, System.DateTime.Now.AddDays(1));
DotNetNuke.Security.PortalSecurity.ClearRoles();
}
if (!Page.IsPostBack)
{
UserInfo cUser = new UserInfo();
cUser = UserController.GetCurrentUserInfo();
if (!UserInfo.IsInRole(PortalSettings.AdministratorRoleName.ToString()) && cUser.IsInRole("Trial"))
{
DotNetNuke.Security.Roles.RoleController rolesController = new DotNetNuke.Security.Roles.RoleController();
UserRoleInfo role = rolesController.GetUserRole(0, _currentUser.UserID, rolesController.GetRoleByName(0, "Trial").RoleID);
expiryDate = role.ExpiryDate;
output.Visible = true;
output.Text = expiryDate.ToString();
}
}
}
catch (Exception ex)
{
DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, ex.ToString(), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
}