本文介绍了调用AddAuthorization不明确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一些简单的策略一直在起作用,直到今天,我很确定我没有做任何事情来破坏它们.在Startup.cs的ConfigureServices中,这是引发错误的代码:

have a few simple policies that had been working up until today, and I'm pretty sure I didn't do anything to break them. In Startup.cs, in ConfigureServices, this is the code that is throwing an error:

services.AddAuthorization(options =>
        {
            options.AddPolicy("AboveUser",
                policy => policy.RequireRole("Admin", "Manager"));
            options.AddPolicy("IsAdmin",
                policy => policy.RequireRole("Admin"));
            options.AddPolicy("IsManager",
                policy => policy.RequireRole("Manager"));
        });

它给我有关AddAuthorization函数的错误:

It gives me this error for the AddAuthorization function:

我不记得最近对我的project.json或类似内容进行了更改,但是如果有帮助,我会在这里引用它:

I can't recall recently making a change to my project.json or anything like that, but I will reference it here if that helps:

{

"dependencies": {
"Microsoft.AspNetCore.Razor.Tools": {
  "version": "1.0.0-preview2-final",
  "type": "build"
},
"Microsoft.EntityFrameworkCore.Tools": {
  "version": "1.0.0-preview2-final",
  "type": "build"
},
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
  "version": "1.0.0-preview2-final",
  "type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
  "version": "1.0.0-preview2-final",
  "type": "build"
},
"BundlerMinifier.Core": "2.2.306",
"Microsoft.ApplicationInsights.AspNetCore": "2.0.0",
"Microsoft.AspNetCore.Authentication.Cookies": "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.Routing": "1.1.0",
"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": "1.1.0",
"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.NETCore.App": "1.1.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0",
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.AspNet.Mvc.Core": "6.0.0-*",
"Microsoft.Extensions.DependencyInjection.Abstractions": "1.1.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": {
"netcoreapp1.0": {
  "imports": [
    "dotnet5.6",
    "portable-net45+win8"
  ]
}
},

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

"runtimeOptions": {
"configProperties": {
  "System.GC.Server": true
}
},
"runtimes": {
"win7-x64":  { }
},

"publishOptions": {
"include": [
  "wwwroot",
  "**/*.cshtml",
  "appsettings.json",
  "web.config"
]
},

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

任何帮助将不胜感激

推荐答案

请勿将beta/rc版本与RTM混合使用!

Don't mix beta/rc versions with RTM!!!

"Microsoft.AspNet.Mvc.Core": "6.0.0-*",

"Microsoft.AspNetCore.Mvc.Core": "1.1.0",

这篇关于调用AddAuthorization不明确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-18 08:25