title: add Rolemanager to config file causes HTTP Error 500.19 - Internal Server Error
body: <p>I create a <strong>Role</strong> for my application and i added this role to the web.config as you can see :</p>
  
  <pre><code>&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="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
    &lt;/configSections&gt;
    &lt;connectionStrings&gt;
      &lt;add name="authentication" connectionString="Data Source=.;Initial Catalog=EducationDB;User ID=sa; password=1" providerName="System.Data.SqlClient" /&gt;
      &lt;add name="EducationDBEntities" connectionString="metadata=res://*/EducationModel.csdl|res://*/EducationModel.ssdl|res://*/EducationModel.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;Data Source=.;Initial Catalog=EducationDB;User ID=sa; password=1;MultipleActiveResultSets=True;App=EntityFramework&amp;quot;" providerName="System.Data.EntityClient" /&gt;
    &lt;/connectionStrings&gt;
    &lt;appSettings&gt;
      &lt;add key="webpages:Version" value="2.0.0.0" /&gt;
      &lt;add key="webpages:Enabled" value="false" /&gt;
      &lt;add key="PreserveLoginUrl" value="true" /&gt;
      &lt;add key="ClientValidationEnabled" value="true" /&gt;
      &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;roleManager enabled="true" /&gt;
      &lt;compilation debug="true" targetFramework="4.5" /&gt;
      &lt;httpRuntime targetFramework="4.5" /&gt;
      &lt;authentication mode="Forms"&gt;
        &lt;forms loginUrl="~/Account/Login" timeout="2880" /&gt;
      &lt;/authentication&gt;
      &lt;pages&gt;
        &lt;namespaces&gt;
          &lt;add namespace="System.Web.Helpers" /&gt;
          &lt;add namespace="System.Web.Mvc" /&gt;
          &lt;add namespace="System.Web.Mvc.Ajax" /&gt;
          &lt;add namespace="System.Web.Mvc.Html" /&gt;
          &lt;add namespace="System.Web.Optimization" /&gt;
          &lt;add namespace="System.Web.Routing" /&gt;
          &lt;add namespace="System.Web.WebPages" /&gt;
        &lt;/namespaces&gt;
      &lt;/pages&gt;
      &lt;!--&lt;membership defaultProvider="AspNetSqlMembershipProvider"&gt;
        &lt;providers&gt;
          &lt;clear /&gt;
          &lt;add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="authentication" /&gt;
        &lt;/providers&gt;
      &lt;/membership&gt;--&gt;
  
      &lt;roleManager defaultProvider="CustomRoleProvider" enabled="true" cacheRolesInCookie="false"&gt;
        &lt;providers&gt;
          &lt;clear /&gt;
          &lt;add name="CustomRoleProvider" type="EducationMVC.Infrastructure.MyRoleProvider"  /&gt;
        &lt;/providers&gt;
      &lt;/roleManager&gt;
  
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;validation validateIntegratedModeConfiguration="false" /&gt;
      &lt;handlers&gt;
        &lt;remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /&gt;
        &lt;remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /&gt;
        &lt;remove name="ExtensionlessUrlHandler-Integrated-4.0" /&gt;
        &lt;add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /&gt;
        &lt;add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /&gt;
        &lt;add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /&gt;
      &lt;/handlers&gt;
    &lt;/system.webServer&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework"&gt;
        &lt;parameters&gt;
          &lt;parameter value="System.Data.SqlServerCe.4.0" /&gt;
        &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
        &lt;provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
    &lt;system.data&gt;
      &lt;DbProviderFactories&gt;
        &lt;remove invariant="System.Data.SqlServerCe.4.0" /&gt;
        &lt;add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" /&gt;
      &lt;/DbProviderFactories&gt;
    &lt;/system.data&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>As you can see this part of code is my role:</p>
  
  <pre><code>&lt;roleManager defaultProvider="CustomRoleProvider" enabled="true" cacheRolesInCookie="false"&gt;
        &lt;providers&gt;
          &lt;clear /&gt;
          &lt;add name="CustomRoleProvider" type="EducationMVC.Infrastructure.MyRoleProvider"  /&gt;
        &lt;/providers&gt;
      &lt;/roleManager&gt;
  </code></pre>
  
  <p>So After running i get this error :</p>
  
  <blockquote>
    <p>Config section 'system.web/roleManager' already defined. Sections must
    only appear once per config file. See the help topic  for
    exceptions  HTTP Error 500.19 - Internal Server Error The requested
    page cannot be accessed because the related configuration data for the
    page is invalid</p>
  </blockquote>
  
  <p>And this part of web.config is highlight :</p>
  
  <pre><code>   47:     &lt;roleManager defaultProvider="CustomRoleProvider" enabled="true" cacheRolesInCookie="false"&gt;
  </code></pre>
  
  <p>What is causing this?</p>
  
  <p>Here is my role that i defined :</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Security;
  using EducationModel;
  
  namespace EducationMVC.Infrastructure
  {
  
      public class MyRoleProvider:RoleProvider
      {
         private readonly EducationDBEntities _dbcontext = new EducationDBEntities();
  
          public override void AddUsersToRoles(string[] usernames, string[] roleNames)
          {
              throw new NotImplementedException();
          }
  
          public override string ApplicationName
          {
              get
              {
                  throw new NotImplementedException();
              }
              set
              {
                  throw new NotImplementedException();
              }
          }
  
          public override void CreateRole(string roleName)
          {
              throw new NotImplementedException();
          }
  
          public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
          {
              throw new NotImplementedException();
          }
  
          public override string[] FindUsersInRole(string roleName, string usernameToMatch)
          {
              throw new NotImplementedException();
          }
  
          public override string[] GetAllRoles()
          {
              throw new NotImplementedException();
          }
  
  
          public override string[] GetRolesForUser(string username)
          {
  
              var objUser = _dbcontext.Users.FirstOrDefault(x =&gt; x.AppUserName == username);
              if (objUser == null)
              {
                  return null;
              }
              else
              {
                  string[] ret = objUser.Roles.Select(x =&gt; x.RoleName).ToArray();
                  return ret;
              }
  
          }
  
  
          public override string[] GetUsersInRole(string roleName)
          {
              throw new NotImplementedException();
          }
  
          public override bool IsUserInRole(string username, string roleName)
          {
              throw new NotImplementedException();
          }
  
          public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
          {
              throw new NotImplementedException();
          }
  
          public override bool RoleExists(string roleName)
          {
              throw new NotImplementedException();
          }
      }
  }
  </code></pre>