I would try adding SimpleMembersihp to the MVC4 website. Not this way. Template code (like C #) is well suited to support it, but web.config is mostly agnostic - devoid of elements that will configure any particular security mechanism. I followed Scott Allen's MVC4 Pluralsight guide - it's a mixed aspnet membership with EF. Maybe I missed something, but C # membership classes did not interact with aspnet-Membership, they did SimpleMembership. So, I deleted aspnet-Membership, but now I can not get the PackageManager for "update-database". He complains: "You must call the WebSecurity.InitializeDatabaseConnection ... method." So, I added the _AppStart.cshtml file with the call, but PM does not seem to know. _AppStart.cshtml:
@using WebMatrix.WebData;
@{
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", true);
}
Web.config:
<appSettings>
<add key="enableSimpleMembership" value="true" />
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<roleManager enabled="true" defaultProvider="simple">
<providers>
<clear/>
<add name="simple" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
</providers>
</roleManager>
<membership defaultProvider="simple">
<providers>
<clear/>
<add name="simple" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
</providers>
</membership
Configuration.cs:
protected override void Seed(eManager.Web.Infrastructure.DepartmentDb context)
{
context.Departments.AddOrUpdate(d => d.Name,
new Department() { Name = "Engineering" },
new Department() { Name = "Sales" },
new Department() { Name = "Shipping" },
new Department() { Name = "Human Resources" }
);
SimpleRoleProvider roles = new WebMatrix.WebData.SimpleRoleProvider();
SimpleMembershipProvider membership = new SimpleMembershipProvider();
if (!roles.RoleExists("Admin"))
{
roles.CreateRole("Admin");
}
}
The role "Admin" is not created.?
source
share