title: Roles.GetRolesForUser(); does not seem to work in MVC 4
body: <p>I'm trying to create a new MVC 4 internet site using the internet template provided in VS2012. I am able to register users for the site and successfully log in and log out. I can see that the SimpleMembership has created 5 tables (UserProfile, webpages_Membership, webpages_OAuthMembership, webpages_Roles, webpages_UsersInRoles) and the logins that I created through the site have been put into the correct places (correct as I expect them anyway!)</p>
  <p>What I am having trouble with is roles of users. Firstly I don't seem to be able to use the old ASP.NET configuration page - it takes forever to load and then when it finally does it gives this error when you click the security link:</p>
  <blockquote>
  <p>There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.</p>
  <p>The following message may help in diagnosing the problem: Unable to connect to SQL Server database.</p>
  </blockquote>
  <p>and this error when you try to do the provider configuration</p>
  <blockquote>
  <p>Could not establish a connection to the database.
  If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider.</p>
  </blockquote>
  <p>I tried running aspnet_regsql which created the old style membership tables along side the newer ones that the site had already created when I registered my first user.</p>
  <p>so to get around that problem as far as creating roles was concerned I put a role into the database myself and put a user in the role. Now running the site I cannot use Roles.GetRolesForUser() either as it also says &quot;Unable to connect to SQL Server database&quot; while debugging (and the YOD gives a null ref exception).</p>
  <p>I notice in web.config that there is no longer a section about membership/roles providers etc that used to be there (eg if you make an MVC 3 internet application)</p>
  <p>I have been searching for answers for days can anyone shed some light on what I might be doing wrong?</p>
  <p>Here is my web.config (with a connection string removed)</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;!--
    For more information on how to configure your ASP.NET application, please visit
    http://go.microsoft.com/fwlink/?LinkId=169433
    --&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
      &lt;section name=&quot;entityFramework&quot; type=&quot;System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&quot; requirePermission=&quot;false&quot; /&gt;
      &lt;sectionGroup name=&quot;dotNetOpenAuth&quot; type=&quot;DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth.Core&quot;&gt;
        &lt;section name=&quot;messaging&quot; type=&quot;DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth.Core&quot; requirePermission=&quot;false&quot; allowLocation=&quot;true&quot; /&gt;
        &lt;section name=&quot;reporting&quot; type=&quot;DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth.Core&quot; requirePermission=&quot;false&quot; allowLocation=&quot;true&quot; /&gt;
        &lt;section name=&quot;oauth&quot; type=&quot;DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth.OAuth&quot; requirePermission=&quot;false&quot; allowLocation=&quot;true&quot; /&gt;
        &lt;section name=&quot;openid&quot; type=&quot;DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth.OpenId&quot; requirePermission=&quot;false&quot; allowLocation=&quot;true&quot; /&gt;
      &lt;/sectionGroup&gt;
    &lt;/configSections&gt;
    &lt;connectionStrings&gt;
      &lt;add name=&quot;DefaultConnection&quot; connectionString=&quot;Data Source=.;Initial Catalog=EnvoyBilling;Integrated Security=True;MultipleActiveResultSets=True;&quot; providerName=&quot;System.Data.SqlClient&quot; /&gt;
      &lt;add name=&quot;EnvoyBillingContext&quot; connectionString=&quot;xxx&quot; providerName=&quot;System.Data.EntityClient&quot; /&gt;
    &lt;/connectionStrings&gt;
    &lt;appSettings&gt;
      &lt;add key=&quot;webpages:Version&quot; value=&quot;2.0.0.0&quot; /&gt;
      &lt;add key=&quot;webpages:Enabled&quot; value=&quot;false&quot; /&gt;
      &lt;add key=&quot;PreserveLoginUrl&quot; value=&quot;true&quot; /&gt;
      &lt;add key=&quot;ClientValidationEnabled&quot; value=&quot;true&quot; /&gt;
      &lt;add key=&quot;UnobtrusiveJavaScriptEnabled&quot; value=&quot;true&quot; /&gt;
      &lt;add key=&quot;enableSimpleMembership&quot; value=&quot;true&quot; /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;compilation debug=&quot;true&quot; targetFramework=&quot;4.5&quot; /&gt;
      &lt;httpRuntime targetFramework=&quot;4.5&quot; /&gt;
      &lt;authentication mode=&quot;Forms&quot;&gt;
        &lt;forms loginUrl=&quot;~/Account/Login&quot; timeout=&quot;2880&quot; /&gt;
      &lt;/authentication&gt;
      &lt;pages&gt;
        &lt;namespaces&gt;
          &lt;add namespace=&quot;System.Web.Helpers&quot; /&gt;
          &lt;add namespace=&quot;System.Web.Mvc&quot; /&gt;
          &lt;add namespace=&quot;System.Web.Mvc.Ajax&quot; /&gt;
          &lt;add namespace=&quot;System.Web.Mvc.Html&quot; /&gt;
          &lt;add namespace=&quot;System.Web.Optimization&quot; /&gt;
          &lt;add namespace=&quot;System.Web.Routing&quot; /&gt;
          &lt;add namespace=&quot;System.Web.WebPages&quot; /&gt;
        &lt;/namespaces&gt;
      &lt;/pages&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;validation validateIntegratedModeConfiguration=&quot;false&quot; /&gt;
      &lt;handlers&gt;
        &lt;remove name=&quot;ExtensionlessUrlHandler-ISAPI-4.0_32bit&quot; /&gt;
        &lt;remove name=&quot;ExtensionlessUrlHandler-ISAPI-4.0_64bit&quot; /&gt;
        &lt;remove name=&quot;ExtensionlessUrlHandler-Integrated-4.0&quot; /&gt;
        &lt;add name=&quot;ExtensionlessUrlHandler-ISAPI-4.0_32bit&quot; path=&quot;*.&quot; verb=&quot;GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS&quot; modules=&quot;IsapiModule&quot; scriptProcessor=&quot;%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll&quot; preCondition=&quot;classicMode,runtimeVersionv4.0,bitness32&quot; responseBufferLimit=&quot;0&quot; /&gt;
        &lt;add name=&quot;ExtensionlessUrlHandler-ISAPI-4.0_64bit&quot; path=&quot;*.&quot; verb=&quot;GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS&quot; modules=&quot;IsapiModule&quot; scriptProcessor=&quot;%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll&quot; preCondition=&quot;classicMode,runtimeVersionv4.0,bitness64&quot; responseBufferLimit=&quot;0&quot; /&gt;
        &lt;add name=&quot;ExtensionlessUrlHandler-Integrated-4.0&quot; path=&quot;*.&quot; verb=&quot;GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS&quot; type=&quot;System.Web.Handlers.TransferRequestHandler&quot; preCondition=&quot;integratedMode,runtimeVersionv4.0&quot; /&gt;
      &lt;/handlers&gt;
    &lt;/system.webServer&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns=&quot;urn:schemas-microsoft-com:asm.v1&quot;&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name=&quot;System.Web.Helpers&quot; publicKeyToken=&quot;31bf3856ad364e35&quot; /&gt;
          &lt;bindingRedirect oldVersion=&quot;1.0.0.0-2.0.0.0&quot; newVersion=&quot;2.0.0.0&quot; /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name=&quot;System.Web.Mvc&quot; publicKeyToken=&quot;31bf3856ad364e35&quot; /&gt;
          &lt;bindingRedirect oldVersion=&quot;0.0.0.0-4.0.0.0&quot; newVersion=&quot;4.0.0.0&quot; /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name=&quot;System.Web.WebPages&quot; publicKeyToken=&quot;31bf3856ad364e35&quot; /&gt;
          &lt;bindingRedirect oldVersion=&quot;1.0.0.0-2.0.0.0&quot; newVersion=&quot;2.0.0.0&quot; /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name=&quot;DotNetOpenAuth.AspNet&quot; publicKeyToken=&quot;2780ccd10d57b246&quot; culture=&quot;neutral&quot; /&gt;
          &lt;bindingRedirect oldVersion=&quot;0.0.0.0-4.1.0.0&quot; newVersion=&quot;4.1.0.0&quot; /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name=&quot;DotNetOpenAuth.Core&quot; publicKeyToken=&quot;2780ccd10d57b246&quot; culture=&quot;neutral&quot; /&gt;
          &lt;bindingRedirect oldVersion=&quot;0.0.0.0-4.1.0.0&quot; newVersion=&quot;4.1.0.0&quot; /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name=&quot;EntityFramework&quot; publicKeyToken=&quot;b77a5c561934e089&quot; culture=&quot;neutral&quot; /&gt;
          &lt;bindingRedirect oldVersion=&quot;0.0.0.0-5.0.0.0&quot; newVersion=&quot;5.0.0.0&quot; /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
      &lt;legacyHMACWarning enabled=&quot;0&quot; /&gt;
    &lt;/runtime&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type=&quot;System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework&quot;&gt;
        &lt;parameters&gt;
          &lt;parameter value=&quot;v11.0&quot; /&gt;
        &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
    &lt;/entityFramework&gt;
    &lt;system.net&gt;
      &lt;defaultProxy enabled=&quot;true&quot; /&gt;
      &lt;settings&gt;
        &lt;!-- This setting causes .NET to check certificate revocation lists (CRL) 
                   before trusting HTTPS certificates.  But this setting tends to not 
                   be allowed in shared hosting environments. --&gt;
        &lt;!--&lt;servicePointManager checkCertificateRevocationList=&quot;true&quot;/&gt;--&gt;
      &lt;/settings&gt;
    &lt;/system.net&gt;
    &lt;dotNetOpenAuth&gt;
      &lt;messaging&gt;
        &lt;untrustedWebRequest&gt;
          &lt;whitelistHosts&gt;
            &lt;!-- Uncomment to enable communication with localhost (should generally not activate in production!) --&gt;
            &lt;!--&lt;add name=&quot;localhost&quot; /&gt;--&gt;
          &lt;/whitelistHosts&gt;
        &lt;/untrustedWebRequest&gt;
      &lt;/messaging&gt;
      &lt;!-- Allow DotNetOpenAuth to publish usage statistics to library authors to improve the library. --&gt;
      &lt;reporting enabled=&quot;true&quot; /&gt;
      &lt;openid&gt;
        &lt;relyingParty&gt;
          &lt;security requireSsl=&quot;false&quot;&gt;
            &lt;!-- Uncomment the trustedProviders tag if your relying party should only accept positive assertions from a closed set of OpenID Providers. --&gt;
            &lt;!--&lt;trustedProviders rejectAssertionsFromUntrustedProviders=&quot;true&quot;&gt;
                          &lt;add endpoint=&quot;https://www.google.com/accounts/o8/ud&quot; /&gt;
                      &lt;/trustedProviders&gt;--&gt;
          &lt;/security&gt;
          &lt;behaviors&gt;
            &lt;!-- The following OPTIONAL behavior allows RPs to use SREG only, but be compatible
                           with OPs that use Attribute Exchange (in various formats). --&gt;
            &lt;add type=&quot;DotNetOpenAuth.OpenId.RelyingParty.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth.OpenId.RelyingParty&quot; /&gt;
          &lt;/behaviors&gt;
        &lt;/relyingParty&gt;
      &lt;/openid&gt;
    &lt;/dotNetOpenAuth&gt;
    &lt;uri&gt;
      &lt;!-- The uri section is necessary to turn on .NET 3.5 support for IDN (international domain names),
               which is necessary for OpenID urls with unicode characters in the domain/host name.
               It is also required to put the Uri class into RFC 3986 escaping mode, which OpenID and OAuth require. --&gt;
      &lt;idn enabled=&quot;All&quot; /&gt;
      &lt;iriParsing enabled=&quot;true&quot; /&gt;
    &lt;/uri&gt;
  &lt;/configuration&gt;
  </code></pre>