我正在使用WebSecurity.InitializeDatabaseConnection('带参数...'),然后我还有一个带有一些属性的用户对象。现在,当我在本地计算机上运行程序时,我的用户表似乎与websecurity在创建所有成员资格表时尝试为我自动创建的用户表合并。所以我没有问题,但是当我尝试将我的网站部署到azure网站时,它不起作用。 websecurity使用自己的User表,包含Id,UserName等,并且它似乎将我的其他用户表重命名为'users'表并带有's'。知道为什么会这样吗?是仅仅是我还是其他人遇到了azure的大量数据库部署问题?它永远不会奏效,非常令人沮丧;工作正常或我的本地机器。
用户对象:
[Table("User")]
public class User : IAuditable, IIdentifiable
{
public User()
{
IsActive = true;
IsDeleted = false;
Friends = new List<Friends>();
SharedFeeds = new List<SharedFeed>();
}
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
public string State { get; set; }
public int ZIPCode { get; set; }
public string UsersTheme { get; set; }
public Boolean IsActive { get; set; }
public Boolean IsDeleted { get; set; }
public virtual List<Friends> Friends { get; set; }
public virtual List<SharedFeed> SharedFeeds { get; set; }
}
在我的InitializeSimpleMembershipAttribute.cs中:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public sealed class InitializeSimpleMembershipAttribute : ActionFilterAttribute
{
private static SimpleMembershipInitializer _initializer;
private static object _initializerLock = new object();
private static bool _isInitialized;
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// Ensure ASP.NET Simple Membership is initialized only once per app start
LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock);
}
private class SimpleMembershipInitializer
{
public SimpleMembershipInitializer()
{
Database.SetInitializer<DataContext>(null);
try
{
using (var context = new DataContext())
{
if (!context.Database.Exists())
{
// Create the SimpleMembership database without Entity Framework migration schema
((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
}
}
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "User", "UserId", "UserName", autoCreateTables: true);
}
catch (Exception ex)
{
throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
}
}
}
似乎这给了我azure的问题:
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "User", "UserId", "UserName", autoCreateTables: true);
我需要使用websecurity,但也能够为用户添加额外的属性