我正在尝试使用SimpleMembershipProvider
. 我在 UserProfile 表中添加了几列,例如手机号码。当我尝试使用手机号码添加用户时,编译器告诉我:
The name 'Mobile' does not exist in the current context
这是课程:
namespace _DataContext.Migrations {
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
using WebMatrix.WebData;
using System.Web.Security;
internal sealed class Configuration : DbMigrationsConfiguration<_DataContext.DataContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
protected override void Seed(_DataContext.DataContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person { FullName = "Rowan Miller" }
// );
//
SeedMembership();
}
private void SeedMembership()
{
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
var roles = (SimpleRoleProvider)Roles.Provider;
var membership = (SimpleMembershipProvider)System.Web.Security.Membership.Provider;
if (!roles.RoleExists("Administrator"))
roles.CreateRole("Administrator");
if (membership.GetUser("Username", false) == null)
membership.CreateUserAndAccount("Username", "Pass", false,
new Dictionary<string, object>
{
{ Mobile = "+311122334455" },
});
/*if (!WebSecurity.UserExists("test"))
WebSecurity.CreateUserAndAccount(
"Username",
"password",
new {
Mobile = "+311122334455",
FirstName = "test",
LastName = "test",
LoginCount = 0,
IsActive = true,
});
*/
}
}
}
如果我使用WebSecurity
一切都很好。
我在这里做错了什么?