Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
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

C#
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
C#
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

SQL
[Authorize(Roles="Stylist")]
    public ActionResult Index()
    {
}



Any help will be much appreciated.. Thanks in advance.
Posted
Updated 4-Dec-13 21:58pm
v4

1 solution

Sorry for the self promotion [not my intention!], but check my following articles...

Custom Membership Providers[^]

Custom Role Providers[^]
 
Share this answer
 
Comments
Divyay208 3-Dec-19 11:53am    
The above article is good... Can you help me for the scenario

1) Legacy webforms application using ASP.Net Provider self service for authenticating and creating users.
2) Now using same database I want to create new MVC application by using same ASP.Net Provider self service.

Is there any way to implement authentication for the above scenario

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900