在调用“WebSecurity”类的任何其他方法之前的WebSecurity.InitializeDatabaseConnection“方法

时间:2014-06-13 18:43:40

标签: asp.net-mvc-5 membership-provider

在我的asp.net mvc项目中,我尝试实施会员提供商来管理帐户和角色

我面对这个堆栈

You must call the "WebSecurity.InitializeDatabaseConnection" method before you call any other method of the "WebSecurity" class. This call should be placed in an _AppStart.cshtml file in the root of your site.

我将此ligne添加到我的Startup.Auth.cs

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); in order to allow

我试图将我的global.asax.cs更改为下面的

using decidata.mennilik.Models;

using System;
using System.Data.Entity;
 using System.Data.Entity.Infrastructure;
 using System.Web.Mvc;
 using System.Web.Optimization;
 using System.Web.Routing;
 using WebMatrix.WebData;


namespace decidata.mennilik
{
public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        AuthConfig.RegisterAuth();


    }
    private static SimpleMembershipInitializer _initializer;
    private static object _initializerLock = new object();
    private static bool _isInitialized;

    private static object _initializerLock = new object();
    private static bool _isInitialized;

    private class SimpleMembershipInitializer
    {
        public SimpleMembershipInitializer()
        {
            Database.SetInitializer<ApplicationDbContext>(null);

            try
            {
                using (var context = new ApplicationDbContext())
                {
                    if (!context.Database.Exists())
                    {
                        // Create the SimpleMembership database without Entity Framework migration schema
                        ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                    }
                }

                WebSecurity.InitializeDatabaseConnection("DefaultConnection", "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);
            }
        }
    }

}

}

但是我遇到了问题       AuthConfig.RegisterAuth(); 我错过了什么吗?

0 个答案:

没有答案