在ASP.NET Core RC2中使用AddAuthentication时出现模糊调用

时间:2016-05-21 13:54:48

标签: asp.net-core jwt openid-connect aspnet-contrib

我已经安装了asp.net core rc 2.我试图创建jwt token auth。在rc 1中,所有工作人员都很好。即使你创建了一个标准项目,他也没有启动,因为有错误=( 纠正错误,我在startup.cs中添加了一个代码:

  public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddApplicationInsightsTelemetry(Configuration);
        var connection = "Data Source=DESKTOP-R3AP4AT\\SQLEXPRESS;Initial Catalog=Guide;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
        services.AddDbContext<GuideContext>(options => options.UseSqlServer(connection));
        services.AddAuthentication();
        services.AddMvc();
    }

添加project.json libs:

"AspNet.Security.OpenIdConnect.Server": "1.0.0-beta4",

并且出现了错误:error 所有project.json:

    {
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0-rc2-3002702",
      "type": "platform"
    },
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview1-final",
    "Microsoft.AspNet.Authentication": "1.0.0-rc1-final",
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0-rc2-final",
    "Microsoft.AspNet.Security.OpenIdConnect" :  "1.0.0-beta3" 

  },

  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    },
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net45+win8+dnxcore50"
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "gcServer": true
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

1 个答案:

答案 0 :(得分:1)

不要将不同的RC版本混合在一起。您的project.json混合了RC1和RC2模块。

所有这些都必须是RC2或者它不会起作用。从旧版本到新版本有十几个重大变化。

"Microsoft.AspNet.Authentication": "1.0.0-rc1-final",
"Microsoft.AspNet.Security.OpenIdConnect" :  "1.0.0-beta3",
"AspNet.Security.OpenIdConnect.Server": "1.0.0-beta4"

这些行是错误的,它们是过时的包。

"Microsoft.AspNetCore.Authentication": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Authentication.OpenIdConnect" :  "1.0.0-rc2-final",
"AspNet.Security.OpenIdConnect.Server": "1.0.0-beta5-final"

应该有效。