2017-03-22 142 views
0

我发现下面的教程如何形成asp.net迁移到asp.net核心运行在Linux上的项目: https://docs.microsoft.com/en-us/aspnet/core/migration/mvc迁移从asp.net到asp.net核心

不幸的是,当我试图“配置身份和会员资格” ,我将代码复制到项目看起来像有没有对.NET核心

例如,这部分这样的命令:

然后,打开Startup.cs和更新ConfigureServices()方法使用 实体框架和身份服务:

public void ConfigureServices(IServiceCollection services) 
{ 
    // Add EF services to the services container. 
    services.AddEntityFramework(Configuration) 
    .AddSqlServer() 
    .AddDbContext<ApplicationDbContext>(); 

    // Add Identity services to the services container. 
    services.AddIdentity<ApplicationUser, IdentityRole>(Configuration) 
    .AddEntityFrameworkStores<ApplicationDbContext>(); 

    services.AddMvc(); 
} 

同样的情况是ApplicationUser.cs

using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 

namespace NewMvc6Project.Models 
{ 
    public class ApplicationUser : IdentityUser 
    { 
    } 
} 

和ApplicationDbContext.cs

using Microsoft.AspNetCore.Identity.EntityFramework; 
using Microsoft.Data.Entity; 

namespace NewMvc6Project.Models 
{ 
    public class ApplicationDbContext : IdentityDbContext<ApplicationUser> 
    { 
    public ApplicationDbContext() 
    { 
     Database.EnsureCreated(); 
    } 

    protected override void OnConfiguring(DbContextOptions options) 
    { 
     options.UseSqlServer(); 
    } 
    } 
} 

它是错的教程或我应该安装一些新的软件包?

+0

,你说有没有ConfigureService方法在启动?你的问题是什么? –

+0

否否。我有ConfigureService方法,但现在我不知道在这种情况下该怎么办: http://scr.hu/2aps/nrpyr http://scr.hu/2aps/g514u http:// scr。 hu/2aps/ozpay http://scr.hu/2aps/29zjc – Halas

+0

'Application.UseSqlServer();'和'OnConfiguring'不需要在'ApplicationDbContext'中, 删除那些,尝试构建并重新启动visual studio to看看错误是否消失。 – NucS

回答

0

我假设你使用VS2015。 因为我在VS2017中尝试了一些扩展方法已经改变。

services.AddEntityFrameworkSqlServer(); 

您是否尝试过升级NuGet中的软件包?

在VS2017

新的Web项目是给包版本1.1.1 ASP.NET核心 作为默认,但VS2015我觉得它给了1.0.0版本