title: Role based authentication in the new MVC 4 Internet template using simplemembership
body: <p>I like the new simplemembership feature in MVC 4 internet template with links to OAuth for external logins in VS 2012 RTM. For the most part authentication feature are working. However even after spending over 8 hours on this I am unable to implement roles based authorization to work on my controllers. SimpleMembership is turning out to be anything but simple.</p>
  
  <p>I have searched stackoverflow, googled and have read the latest by <a href="http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx" rel="noreferrer">John Galloway</a>, tried many suggestions and still have not been able to resovle this issue. It all started with getting Sql connection error and could not figure out why when the connection string and everything else was good. It took many hours to figure out the it is Roles class that is causing problem.</p>
  
  <p>The [Authorize] attribute on controllers works as before for basic authentication. But any time I try to use Roles it give sql connection error (because it reverts to the old DefaultRolesProvider which tries to connect to default SqlExpress aspnetdb file and fails). So something like:</p>
  
  <pre><code>[Authorize(Roles="admin")]
  </code></pre>
  
  <p>does not work. It will work if I go back to the old asp.net membership providers, but then I lose the simple database tables, token bases confirmation and recovery, more secure password hashing and more importantly external logins via OAuth.</p>
  
  <p>The only thing that works inside code and razor views is </p>
  
  <pre><code>User.IsInRole("admin")
  </code></pre>
  
  <p>which is OK for menu items and such, but ver cumbersome to implement inside every single Action in controller (and I do not like that it only tests for single role at a time).</p>
  
  <p>I will greatly appreciate any guidance to resovle this issue.</p>