How to enabling and creating roles in mvc`

Total Post:117

 2004  View(s)
Rate this:

How to enable roles in mvc?? my code is given below and i dont know how to create roles and i want to add it to the databse..

    public class UserRightAttribute : ActionFilterAttribute
        public override void OnActionExecuting(ActionExecutingContext filterContext)
            //write your user right logic
            //if user has right to do nothig otherwise redirect to error page.
            string message = "It seems You  are not authorize to view this part of the web site!!!.";
            RouteValueDictionary redirectTargetDictionary = new RouteValueDictionary();
            redirectTargetDictionary.Add("area", "");
            redirectTargetDictionary.Add("action", "SaveData");
            redirectTargetDictionary.Add("controller", "Home");
            redirectTargetDictionary.Add("customMessage", message);
            filterContext.Result = new RedirectToRouteResult(redirectTargetDictionary);

  1. Post:101

    Re: How to enabling and creating roles in mvc`

    Hi jay

    First web.config add following

        <roleManager enabled="true" />

    Adding roles is the same like ASP.NET for example

    Roles.AddUserToRole("userName", "RoleName");

      Modified On Apr-07-2018 12:32:05 AM