I have something like this:
FormsAuthentication.SetAuthCookie(user, false);
var tmp = Roles.IsUserInRole("administrator");
var _tmp = Roles.IsUserInRole(user, "administrator");
tmp is always false, and _tmp is always true. Why is tmp false?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since you are doing this during a login action, it’s safe to assume the user is not logged in yet, and thus the
UseronHttpContext(accessible from your controller viathis.Useror justUser) is set to an unauthenticated principal.Roleswill use the currentUser.Identity.Nameto get the username and retrieve roles, so in this case, you’d want to use the second overload.If you need to use the first overload for some reason, you’d have to update user:
Normally, the FormsAuth module would update the
Userappropriately the next time the user visits a page after logging in, by reading the auth ticket cookie, decrypting it, and creating a newGenericPrincipalwith aFormsIdentityusing the name found in the ticket.