title: Creating a AuthorizeAttribute - what do I need to know?
body: <p>Here are my requirements:</p>
  
  <ul>
  <li><p>I'll be adding users to N amount of roles; defined in a database. </p></li>
  <li><p>I need to protect each controller action with my authorize attribute.</p></li>
  </ul>
  
  <p>For example, the web application would check if the logged in user belongs to either of these two roles and if they do, I let them in. <strong>How can I tell the Authorize attribute to fetch the user roles from a database table I choose?</strong></p>
  
  <pre><code> [Authorize(Roles = "Admin, Technician")]
   public ActionResult Edit(int id)
   {
       return View();
   }
  </code></pre>
  
  <p>I've tried Googling for many different pages, but none seem to fit in with what I need and are overly complicated.</p>
  
  <p>If the <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.authorizeattribute.aspx" rel="nofollow noreferrer">official documentation</a> has something I'd love to find it as well, as I didn't see anything I could use.</p>
  
  <p>Any suggestions?</p>
  
  <p>For example, this question has a very clean looking answer, but I don't know if it's complete or missing something important.</p>
  
  <p><a href="https://stackoverflow.com/questions/7286379/asp-net-mvc3-role-and-permission-management-with-runtime-permission-assignmen">ASP.NET MVC3 Role and Permission Management -&gt; With Runtime Permission Assignment</a></p>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <p>It seems that what I'm actually looking for is creating a custom role provider, correct? Do I <em>need</em> to implement this class and use it as my Role provider? I'm fairly new at this, any thoughts?</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/8fw7xh74.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/8fw7xh74.aspx</a></p>