ASP.NET MVC 4, The “WebSecurity.InitializeDatabaseConnection” method can be called only once

后端 未结 5 1590
迷失自我
迷失自我 2020-12-19 07:00

I am developing a code first web app in Visual Studio 2012 Express.

I use this connection string in the web.config:



        
5条回答
  •  囚心锁ツ
    2020-12-19 07:32

    Add this code to Global.asax.cs. This will makes sure that your database is always Initialized before any other executions. Also make sure its the first registration in Application_Start()

    if (!WebSecurity.Initialized)
                    WebSecurity.InitializeDatabaseConnection("DefaultConnection",
    "UserProfile", "UserId", "UserName", autoCreateTables: true);
    

    Get rid of Filters/InitializeSimpleMembershipAttribute.cs or just comment the code inside, in case you would like to go back to it.

    Remove [InitializeSimpleMembership] at the top of AccountController.cs

    Also if you haven't already enabled migrations, i would encourage you do so. That way, you can do your seeds in Configuration.cs created inside the Migration folder when you run Enable-Migrations

提交回复
热议问题