Questions tagged «asp.net-core-2.0»


28
升级到ASP.NET Core 2.0后无法创建迁移
升级到ASP.NET Core 2.0后,我似乎无法再创建迁移。 我越来越 “在类'Program'上调用方法'BuildWebHost'时发生错误。在没有应用程序服务提供商的情况下继续。错误:发生一个或多个错误。(登录名无法打开数据库“ ...”。登录失败。登录用户'...'失败 和 “无法创建类型为'MyContext'的对象。将'IDesignTimeDbContextFactory'的实现添加到项目中,或者在设计时参见 https://go.microsoft.com/fwlink/?linkid=851728&clcid=0x804。 我以前运行的命令是$ dotnet ef migrations add InitialCreate --startup-project "..\Web"(来自具有DBContext的项目/文件夹)。 连接字符串: "Server=(localdb)\\mssqllocaldb;Database=database;Trusted_Connection=True;MultipleActiveResultSets=true" 这是我的Program.cs public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .Build(); }


2
ASP.NET Core 2.0身份验证中间件
使用Core 1.1遵循@blowdart的建议并实现了自定义中间件: https://stackoverflow.com/a/31465227/29821 它像这样工作: 中间件运行了。从请求标头中提取一个令牌。 验证令牌,如果有效,则建立一个包含多个声明的身份(ClaimsIdentity),然后通过HttpContext.User.AddIdentity()添加它; 在使用services.AddAuthorization的ConfigureServices中,我添加了一个策略来要求由中间件提供的声明。 然后,在控制器/操作中,我将使用[Authorize(Roles =“中间件添加的某些角色”)] 这在2.0上适用,但是如果令牌无效(上面的步骤2)并且从不添加声明,则会得到“未指定authenticationScheme,并且未找到DefaultChallengeScheme”的信息。 所以现在我正在阅读auth在2.0中更改了: https://docs.microsoft.com/zh-cn/aspnet/core/migration/1x-to-2x/identity-2x 在ASP.NET Core 2.0中执行相同操作的正确方法是什么?我没有看到进行真正的自定义身份验证的示例。

2
使用多个JWT承载身份验证
是否可以在ASP.NET Core 2中支持多个JWT令牌发行者?我想提供一个用于外部服务的API,并且需要使用两种JWT令牌来源-Firebase和自定义JWT令牌发行者。在ASP.NET核心中,我可以为Bearer身份验证方案设置JWT身份验证,但只能为一个授权设置: services .AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.Authority = "https://securetoken.google.com/my-firebase-project" options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidIssuer = "my-firebase-project" ValidateAudience = true, ValidAudience = "my-firebase-project" ValidateLifetime = true }; } 我可以有多个发行人和受众,但不能设置多个授权机构。

4
无法解析来自根提供商.Net Core 2的范围服务
当我尝试运行我的应用程序时出现错误 InvalidOperationException: Cannot resolve 'API.Domain.Data.Repositories.IEmailRepository' from root provider because it requires scoped service 'API.Domain.Data.EmailRouterContext'. 奇怪的是,据我所知,这个EmailRepository和接口的设置与我所有其他存储库完全相同,但没有引发任何错误。仅当我尝试使用该应用程序时,才会发生该错误。线。这是我的一些Startup.cs文件。 public class Startup { public IConfiguration Configuration { get; protected set; } private APIEnvironment _environment { get; set; } public Startup(IConfiguration configuration, IHostingEnvironment env) { Configuration = configuration; _environment = APIEnvironment.Development; if (env.IsProduction()) _environment = …

2
如何在.NET Core 3.0中替换AddJwtBearer扩展
我有以下代码可以在.NET Core 2.2中进行编译和工作: byte[] key = Encoding.ASCII.GetBytes(Constants.JWT_SECRET); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = true; x.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(key), ValidateIssuer = false, ValidateAudience = false }; }); 在.NET Core 3.0中,出现错误: 错误CS1061'AuthenticationBuilder'不包含'AddJwtBearer'的定义,并且找不到可以接受的扩展方法'AddJwtBearer'接受类型为'AuthenticationBuilder'的第一个参数(您是否缺少using指令或程序集引用?) …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.