Hello guys,
I searched a lot on web but couldn't get a solution finally i am here.
I am using authentication and authorizzation in MVC .
here i dont want to use asp.net role provider.
I created my own table in which i am having Roles (A,B). now at the time of authentication I am checking user credentials from my another table in which i am having user information if it returns true it means user authentication successfull.
now after successfull authentication i am fetching role from my roles table based on userid.
this role i want to assign to authenticated user
Not getting any success.
For this i am using following code
string userRole = _userService.GetUserRole(data.Email);
FormsAuthenticationTicket authenticationTicket = new FormsAuthenticationTicket(1, data.Email, DateTime.Now, DateTime.Now.AddMinutes(20), data.IsRemember, userRole, "/");
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authenticationTicket));
Response.Cookies.Add(cookie);
If i am using above code problem is i had to check in each contoller action
if session exist
{
if((((FormsIdentity)HttpContext.User.Identity).Ticket).UserData == UserConstants.STYLIST)
}
instead i only want to assign role after authentication and then use mvc attribute which checks itself role of user not from database it should check from ticket like below
[Authorize(Roles="Stylist")]
public ActionResult Index()
{
}
Any help will be much appreciated.. Thanks in advance.