问题从AspNetCore Identity 1.0更新到1.1

时间:2016-12-05 09:56:13

标签: asp.net-core authorization asp.net-identity

当我将Microsoft.AspNetCore.Identity.EntityFrameworkCore从1.0更新为1.1时,[Authorize]属性无法重定向到登录页面,我只是得到一个空白页面。

是否有人知道是否有任何可能导致此问题的重大变化?

我使用默认/帐户/登录

services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
    options.Password.RequireDigit = Configuration.GetValue<bool>("Identity:Password:RequireDigit");
    options.Password.RequiredLength = Configuration.GetValue<int>("Identity:Password:RequiredLength");
    options.Password.RequireLowercase = Configuration.GetValue<bool>("Identity:Password:RequireLowercase");
    options.Password.RequireNonAlphanumeric = Configuration.GetValue<bool>("Identity:Password:RequireNonAlphanumeric");
    options.Password.RequireUppercase = Configuration.GetValue<bool>("Identity:Password:RequireUppercase");

    options.Lockout.MaxFailedAccessAttempts = Configuration.GetValue<int>("Identity:Lockout:MaxFailedAccessAttempts"); ;

    options.SignIn.RequireConfirmedEmail = Configuration.GetValue<bool>("Identity:SignIn:RequireConfirmedEmail");

    options.User.RequireUniqueEmail = Configuration.GetValue<bool>("Identity:User:RequireUniqueEmail");


})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();

我可以使用样板VS 2015项目复制这个。

  1. 新项目
  2. ASP.NET核心Web应用程序(.NET核心)
  3. '网络应用'模板
  4. '个人用户帐户'身份验证
  5. 将网站打开到/ Manage / Index,它将重定向到/ Account / Login
  6. 将这些设置为1.1

    “Microsoft.AspNetCore.Authentication.Cookies”:“1.1.0”

    “Microsoft.AspNetCore.Identity.EntityFrameworkCore”:“1.1.0”

    “Microsoft.Extensions.Logging”:“1.1.0”

  7. 打开网站/管理/索引,它将打开一个空白页

  8. 我使用的是.NET 4.6.1,这是更新的project.json

    {
      "userSecretsId": "aspnet-MPS.IdentityServer-3b3bb17d-2d5b-4d07-a62f-0c092febc156",
    
      "dependencies": {
        "AspNet.Security.OAuth.Validation": "1.0.0-alpha3-final",
        "esendex-dotnet-sdk": "2.5.0",
        "MailKit": "1.10.1",
        //"Microsoft.AspNet.WebApi.Core": "5.2.3",
        "Microsoft.AspNetCore.Authentication.Cookies": "1.1.0",
        //"Microsoft.AspNetCore.Authentication.Facebook": "1.0.0",
        //"Microsoft.AspNetCore.Authentication.Google": "1.0.0",
        //"Microsoft.AspNetCore.Authentication.Twitter": "1.0.0",
        "Microsoft.AspNetCore.Cors": "1.1.0",
        "Microsoft.AspNetCore.Diagnostics": "1.1.0",
        "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.1.0",
        "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.0",
        "Microsoft.AspNetCore.Mvc": "1.1.0",
        "Microsoft.AspNetCore.Razor.Tools": {
          "version": "1.1.0-preview4-final",
          "type": "build"
        },
        "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
        "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
        "Microsoft.AspNetCore.StaticFiles": "1.1.0",
        "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
        "Microsoft.EntityFrameworkCore.SqlServer.Design": {
          "version": "1.1.0",
          "type": "build"
        },
        "Microsoft.EntityFrameworkCore.Tools": {
          "version": "1.1.0-preview4-final",
          "type": "build"
        },
        "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
        "Microsoft.Extensions.Configuration.Json": "1.1.0",
        "Microsoft.Extensions.Configuration.UserSecrets": "1.1.0",
        "Microsoft.Extensions.Logging": "1.1.0",
        "Microsoft.Extensions.Logging.Console": "1.1.0",
        "Microsoft.Extensions.Logging.Debug": "1.1.0",
        "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
        "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0",
        "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
          "version": "1.1.0-preview4-final",
          "type": "build"
        },
        "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
          "version": "1.1.0-preview4-final",
          "type": "build"
        },
        "OpenIddict": "1.0.0-*",
        "OpenIddict.Mvc": "1.0.0-*",
        "Serilog.Extensions.Logging": "1.1.0",
        "Serilog.Settings.Configuration": "2.1.0",
        "Serilog.Sinks.RollingFile": "2.2.0",
        "System.Reflection.Extensions": "4.0.0"
      },    
    
      "tools": {
        "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
        "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
        "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
        "Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
        "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
          "version": "1.0.0-preview2-final",
          "imports": [
            "portable-net45+win8"
          ]
        }
      },    
    
      "frameworks": {
        "net461": {}
      },
    
      "buildOptions": {
        "emitEntryPoint": true,
        "preserveCompilationContext": true
      },    
    
      "runtimeOptions": {
        "configProperties": {
          "System.GC.Server": true
        }
      },    
    
      "publishOptions": {
        "include": [
          "wwwroot",
          "Views",
          "Areas/**/Views",
          "appsettings*.json",
          "web.config"
        ],
        "exclude": [
          "wwwroot/lib/",
          "wwwroot/_references.js",
          "wwwroot/css/src",
          "wwwroot/css/bootstrap-override.css",
          "wwwroot/js/src",
          "Views/Account/ExternalLoginConfirmation.cshtml",
          "Views/Account/ExternalLoginFailure.cshtml",
          "Views/Manage/ManageLogins.cshtml",
          "Views/Manage/SetPassword.cshtml"
        ]
      },    
    
      "scripts": {
        "prepublish": [ "bower install" ],
        "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
      },
    
      "configurations": {
        "Test": {}
      }        
    }
    

1 个答案:

答案 0 :(得分:3)

更新以下内容:

"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",

"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",

我怎么弄清楚:我通过Kestrel跑来获取命令行输出窗口,希望看到错误。相反,它奏效了。所以我意识到IIS集成部分必须有新的东西。