Hi, I am trying the new AspNet Identity functionality, and I am puzzled by the following.
Using a new Visual Studio 2013, ASP.NET Web Application (webforms) with standard Identity model, just local user accounts, nothing external. Creating new users and saving them to the database through Entity Framework works no problems.
However, executing the following code attached to OnClick event of an aspx page button, I would expect the currently logged in user to receive the “Admin” claim, of the role type.
protected void btnMakeAdmin_Click(object sender, EventArgs e) { var manager = new UserManager(); if (manager.SupportsUserClaim) if (!User.IsInRole("Admin")) manager.AddClaimAsync(Context.User.Identity.GetUserId(), new Claim(ClaimTypes.Role, "Admin")); bool success = User.IsInRole("Admin"); }
Alas, nothing happens, there are no changes in the AspNetRoles, AspNetUserClaims, nor AspNetUserRoles tables.
Furthermore, the success Boolean variable is false, even though AddClaimAsync definitely runs.
What is wrong?
Thank you