---
title: "How to create role and enable role in mvc?"  
description: "How to create role and enable role in mvc?"  
author: "Jayden Bell"  
published: 2014-10-06  
updated: 2014-10-06  
canonical: https://www.mindstick.com/forum/2317/how-to-create-role-and-enable-role-in-mvc  
category: "asp.net mvc"  
tags: ["asp.net", "asp.net mvc"]  
reading_time: 1 minute  

---

# How to create role and enable role 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 don't 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 database.

\

```
[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

First web.config add following.

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

Adding roles is the same like ASP.NET for example\

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