title: ASP.NET MVC Forms Authentication + Authorize Attribute + Simple Roles
body: <p>I'm trying to add <em>simple</em> Authentication and Authorization to an ASP.NET MVC application.</p>
  
  <p>I'm just trying to tack on some added functionality to the basic Forms Authentication (due to simplicity and custom database structure)</p>
  
  <p>Assuming this is my database structure:
  User:
    username
    password
    role (ideally some enum. Strings if need be. Currently, user only has ONE role, but this might change)</p>
  
  <p>High Level Problem:
  Given the above database structure, I would like to be able to do the following:</p>
  
  <ul>
  <li>Simple Login using Forms Authentication</li>
  <li>Decorate my actions with:
  [Authorize(Roles={ MyRoles.Admin, MyRoles.Member})]</li>
  <li>Use roles in my Views (to determine links to display in some partials)</li>
  </ul>
  
  <p>Currently, all I'm really sure of is how to Authenticate. After that I'm lost. I'm not sure at which point do I grab the user role (login, every authorization?). Since my roles may not be strings, I'm not sure how they will fit in with the User.IsInRole().</p>
  
  <p>Now, I'm asking here because I haven't found a "simple" accomplish what I need. I have seen multiple examples.</p>
  
  <p>For Authentication:</p>
  
  <ul>
  <li>We have simple user validation that checks the database and "SetAuthCookie"</li>
  <li>Or we override the Membership provider and do this inside of ValidateUser
  In either of these, I'm not sure how to tack on my simple user Roles, so that they work with the:
  HttpContext.Current.User.IsInRole("Administrator")
  Furthermore, I'm not sure how to modify this to work with my enum values.</li>
  </ul>
  
  <p>For Authorization, I've seen:</p>
  
  <ul>
  <li>Deriving AuthorizeAttribute and implementing AuthorizeCore OR OnAuthorization to handle roles?</li>
  <li>Implementing IPrincipal?</li>
  </ul>
  
  <p>Any assistance would be greatly appreciated. However, I fear I may need a lot of detail, because none of what I've Googled seems to fit with what I need to do.</p>