“尚未启用角色管理器功能。”在web.config中

时间:2013-11-27 11:09:37

标签: c# asp.net-mvc-4 roles roleprovider

我有一个MVC4应用程序,它将模型和迁移放在一个单独的项目中,这是一个类库。

我的种子方法中有这个:

protected override void Seed(BDOleoTorres.Models.OleoTorresContext context)
    {
                if (!Roles.RoleExists("Admin"))
            Roles.CreateRole("Admin");
            //[Authorize(Roles = "Admin,Vendedor,Administrativo")]
            if (!WebSecurity.UserExists("Administrador"))
            WebSecurity.CreateUserAndAccount(
                "Administrador",
                "Admin123.",
                new { NrVendedor = 1, DataHoraCriacao = DateTime.Now, NomeHumano = "Sr Administrador", TipoUser="Geral" });

        if (!Roles.GetRolesForUser("Administrador").Contains("Admin"))
            Roles.AddUsersToRole(new string[] { "Administrador" }, "Admin");

    }

这在我的web.config(其他项目)中:

<system.web>
<roleManager enabled="true" defaultProvider="SimpleRoleProvider">
  <providers>
    <clear />
    <add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
  </providers>
</roleManager>
<membership defaultProvider="SimpleMembershipProvider">
  <providers>
    <clear />
    <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
  </providers>
</membership>

我正确迁移,但是update-database -verbose何时出错:

The Role Manager feature has not been enabled.

0 个答案:

没有答案