I am writing a controller as shown below:
public class AccountController : Controller
{
public ActionResult Login()
{
GenericIdentity identity = new GenericIdentity("userName");
GenericPrincipal principal = new GenericPrincipal(identity, new string[] { "role1", "role2" });
this.HttpContext.User = principal;
;
}
}
After logging in, I can get the user name User.Identity.Name in another controller. But User.IsInRole ("role1") always returns false.
How can I assign a value to a user, I donβt want to use membership ...
source
share