Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 如何在个人登录ASP.NET MVC 6中使用SQL Server_Asp.net Mvc_Asp.net Core Mvc_Visual Studio 2015 - Fatal编程技术网

Asp.net mvc 如何在个人登录ASP.NET MVC 6中使用SQL Server

Asp.net mvc 如何在个人登录ASP.NET MVC 6中使用SQL Server,asp.net-mvc,asp.net-core-mvc,visual-studio-2015,Asp.net Mvc,Asp.net Core Mvc,Visual Studio 2015,我正在VS2015预览版上工作,我被登录卡卡住了。。比如在ASP.NET MVC VS2013中,我们可以通过SimpleMembershipInializer登录,例如 public SimpleMembershipInitializer() { Database.SetInitializer<LoginEntities>(null); try { using (var context = new LoginEntities())

我正在VS2015预览版上工作,我被登录卡卡住了。。比如在ASP.NET MVC VS2013中,我们可以通过SimpleMembershipInializer登录,例如

public SimpleMembershipInitializer()
{
    Database.SetInitializer<LoginEntities>(null);

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

        WebSecurity.InitializeDatabaseConnection("LoginEntities", "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);
    }
public SimpleMembershipInitializer()
{
Database.SetInitializer(null);
尝试
{
使用(var context=new loginenties())
{
如果(!context.Database.Exists())
{
//创建没有实体框架迁移模式的SimpleMembership数据库
((IObjectContextAdapter)context.ObjectContext.CreateDatabase();
}
}
WebSecurity.InitializeDatabaseConnection(“loginenties”、“UserProfile”、“UserId”、“UserName”、autoCreateTables:true);
}
捕获(例外情况除外)
{
抛出新的InvalidOperationException(“无法初始化ASP.NET简单成员身份数据库。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=256588“,ex);
}
所以我在VS2015做的就像

 public class EBuilderUesr : IdentityUser<string, AspNetUserLogin, AspNetUserRole,AspNetUserClaim>
{
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<EBuilderUesr> manager)
    {
        // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here
        return userIdentity;
    }
}

public class AspNetUserRole : IdentityUserRole<string> { }
public class AspNetRole : IdentityRole<string, AspNetUserRole> { }
public class AspNetUserClaim : IdentityUserClaim<string> { }
public class AspNetUserLogin : IdentityUserLogin<string> { }
public class AspNetUser : IdentityUserLogin<string> { }

public class ApplicationDbContext : IdentityDbContext<EBuilderUesr, AspNetRole, string,AspNetUserLogin,AspNetUserRole,AspNetUserClaim>
{
    public ApplicationDbContext()
        : base("BuilderTrackerEntities")
    {
    }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
}
公共类ebuilderUser:IdentityUser
{
公共异步任务GenerateUserIdentityAsync(用户管理器)
{
//注意authenticationType必须与CookieAuthenticationOptions.authenticationType中定义的类型匹配
var userIdentity=wait manager.CreateIdentityAsync(这是DefaultAuthenticationTypes.ApplicationOkie);
//在此处添加自定义用户声明
返回用户身份;
}
}
公共类AspNetUserRole:IdentityUserRole{}
公共类AspNetRole:IdentityRole{}
公共类AspNetUserClaim:IdentityUserClaim{}
公共类AspNetUserLogin:IdentityUserLogin{}
公共类AspNetUser:IdentityUserLogin{}
公共类ApplicationDbContext:IdentityDbContext
{
公共应用程序上下文()
:base(“BuilderTrackerEntities”)
{
}
公共静态应用程序上下文创建()
{
返回新的ApplicationDbContext();
}
}
现在进入IdentityConfig.cs是

public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context) 
        {
            //var manager = new ApplicationUserManager(new UserStore<EBuilderUesr>(context.Get<ApplicationDbContext>()));
            var manager = new ApplicationUserManager(new UserStore<EBuilderUesr, AspNetRole, string, AspNetUserLogin, AspNetUserRole, AspNetUserClaim>(context.Get<ApplicationDbContext>()));
}
公共静态应用程序服务器管理器创建(IdentityFactoryOptions选项,IOwinContext上下文)
{

//var manager=newapplicationUserManager(newuserstore(context.Get());
var manager=newapplicationUserManager(newuserstore(context.Get()); }
获取上述ApplicationUserManager上的错误

我还更改了配置文件中的连接字符串,但仍然出现了一个获取错误,如

请让我知道。我会做错什么

谢谢,,
_jitendra

能否显示用于创建
UserManagerFactory
的代码?var manager=new ApplicationUserManager(new UserStore(context.Get());这会给我带来错误,我不确定我错在哪里。