forum

Home / DeveloperSection / Forums / How to create role and enable role in mvc?

How to create role and enable role in mvc?

Jayden Bell178306-Oct-2014

How to enable roles in mvc?? my code is given below and i don't know how to create roles and i want to add it to the database.


[AttributeUsage(AttributeTargets.All)]
        publicclassUserRightAttribute : ActionFilterAttribute
        {
            publicoverridevoid 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 = newRedirectToRouteResult(redirectTargetDictionary);
            }
        }


Updated on 06-Oct-2014

Can you answer this question?


Answer

1 Answers

Liked By