---
title: "How to enabling and creating roles in mvc`"  
description: "How to enabling and creating roles in mvc`"  
author: "Anonymous User"  
published: 2014-11-21  
updated: 2014-11-22  
canonical: https://www.mindstick.com/forum/12677/how-to-enabling-and-creating-roles-in-mvc  
category: "asp.net mvc"  
tags: ["c#", "mvc4", "authentication", "authorization"]  
reading_time: 1 minute  

---

# How to enabling and creating roles in mvc`

How to enable [roles](https://www.mindstick.com/articles/1366/membership-roles-user-profile-in-asp-dot-net) in [mvc](https://www.mindstick.com/forum/155803/define-cache-profile-in-mvc)?? my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) is given below and i dont know how to create roles and i want to [add](https://www.mindstick.com/forum/12983/add-address-in-textbox-when-page-is-load-and-if-i-search-address-in-textbox-show-in-map-by-javascript) it to the databse..

```
[AttributeUsage(AttributeTargets.All)]    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);        }    }
```

## Replies

### Reply by Anonymous User

Hi jay

**First web.config add following**

```
<system.web>    <roleManager enabled="true" />    ...
```

Adding roles is the same like ASP.NET for example

```
Roles.CreateRole("RoleName");Roles.AddUserToRole("userName", "RoleName");
```


---

Original Source: https://www.mindstick.com/forum/12677/how-to-enabling-and-creating-roles-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
