我想在MVC4中使用註冊和登錄表單。我已經使用實體框架從數據庫創建模型,現在我想生成成員表,但我已經嘗試了很多東西,我仍然無法訪問它們。如何訪問mvc4中的成員資格表?
我有2個連接字符串:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-Projekti-20160917211151;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-Projekti-20160917211151.mdf" providerName="System.Data.SqlClient" />
<add name="UniversitetiEntities" connectionString="metadata=res://*/Models.Universiteti.csdl|res://*/Models.Universiteti.ssdl|res://*/Models.Universiteti.msl;provider=System.Data.SqlClient;provider connection string="data source=ARBERS-PC\BERSANTA;initial catalog=Universiteti;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> </connectionStrings>
帳號模型我改變了UniversitetiEntities基地:
public class UsersContext : DbContext
{
public UsersContext()
: base("UniversitetiEntities")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
}
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
}
我也做這個昌InitializeSimpleMembershipAttribute文件:
private class SimpleMembershipInitializer
{
public SimpleMembershipInitializer()
{
Database.SetInitializer<UsersContext>(null);
try
{
using (var context = new UsersContext())
{
if (!context.Database.Exists())
{
// Create the SimpleMembership database without Entity Framework migration schema
((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
}
}
WebSecurity.InitializeDatabaseConnection("UniversitetiEntities", "UserProfile", "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);
}
}
}
}
但它總是拋出這個異常:ASP.NET簡單成員資格數據庫c不能初始化。
我改變它在「DefaultConnection」但我仍然得到這個錯誤:「System.InvalidOperationException」類型的異常出現在Projekti.dll但在用戶代碼中沒有處理 –
請編輯您的問題包括你的錯誤,因爲'InvalidOperationException'可能由應用的某些條件觸發,指定異常詳細信息和堆棧跟蹤(如果有的話)。 –