除了使用“ASP.NET Core”标记外,还可以将此标记用于与ASP.NET Core 2.0特别相关的问题。
如何使用ASP.Net core ModelMetadata属性
[表(“法律实体”)] [ModelMetadataType(typeof(LegalEntityMeta))] 公共类 LegalEntity :实体 { } 公共类 LegalEntityMeta { [JsonProperty(PropertyName = "LegalEntityId...
如何定义从以下 API 生成的 swagger 中的属性的默认值? 公共类搜索查询 { 公共字符串 OrderBy { 获取;放; } [默认值(订单方向.描述...
此项目使用的 Microsoft.NET.Sdk 版本不足以支持对面向 .NET Standard 1.5 或更高版本的库的引用
我遇到以下构建错误: 此项目使用的 Microsoft.NET.Sdk 版本不足以支持对面向 .NET Standard 1.5 或更高版本的库的引用。拜...
在 ASP.Net Core 2 MVC 中禁用模型验证的正确方法
使用扩展方法设置 MVC services.AddMvc() 然后在控制器中(这也可能适用于 GET),使用主体中提供的参数创建 POST 操作的方法,例如 [http...
IdentityServer4 Net Core 2 不调用自定义 iProfileService
我已将 Identity Server 项目升级到 Net Core 2,现在我无法调用 iProfileService 对象来添加自定义用户声明。它在 Net Core 1 中确实有效。 启动.cs
没有为方案“Cookies”注册身份验证处理程序。注册的方案有:Application、Bearer、ASOS
我正在使用.net core 2.1应用程序实现Aspnet.security.openidconnect(ASOS)。现在的问题是当我尝试在控制器中执行这个块时, 公共异步任务 我正在使用 .net core 2.1 应用程序实现 Aspnet.security.openidconnect (ASOS)。现在的问题是当我尝试在控制器中执行这个块时, public async Task<IActionResult> Authorize() { if (Response.StatusCode != 200) { return View("AuthorizeError"); } var ticket = await AuthenticationHttpContextExtensions.AuthenticateAsync(HttpContext, CookieAuthenticationDefaults.AuthenticationScheme); var identity = ticket != null && ticket.Principal != null ? ticket.Ticket.Principal : null; if (identity == null) { await AuthenticationHttpContextExtensions.ChallengeAsync(HttpContext, CookieAuthenticationDefaults.AuthenticationScheme, null); return Unauthorized(); } ViewData["Name"] = ticket.Principal.Identity.Name; var scopes = (HttpContext.Request.Query["scope"].ToString() ?? "").Split(' '); ViewData["Scopes"] = scopes; //var claimsIdentity = new ClaimsIdentity(identity.Claims, "Bearer", identity.NameClaimType, identity.RoleClaimType); var claimsIdentity = new ClaimsIdentity(identity.Claims, "Bearer"); foreach (var scope in scopes) { claimsIdentity.AddClaim(new Claim("urn:oauth:scope", scope)); } var claimsPrincipal = new ClaimsPrincipal(claimsIdentity); await AuthenticationHttpContextExtensions.SignInAsync(HttpContext, claimsPrincipal); logger.Info("Authorize request received"); return View(); } 我在这条线上遇到的错误: var ticket = await AuthenticationHttpContextExtensions.AuthenticateAsync(HttpContext, CookieAuthenticationDefaults.AuthenticationScheme); 下面是ASOS在启动时的实现: services.Configure<CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie("Application", options => { options.LoginPath = new PathString(LoginPath); options.LogoutPath = new PathString(LogoutPath); options.ExpireTimeSpan = TimeSpan.FromMinutes(5); //options.AccessDeniedPath = new PathString(); }); //services.AddAuthentication("External") // .AddCookie("Cookies", options => // { // options.Cookie.Name = CookieAuthenticationDefaults.CookiePrefix + "External"; // options.ExpireTimeSpan = TimeSpan.FromMinutes(5); // }); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(); services.AddAuthentication(OAuthValidationDefaults.AuthenticationScheme).AddOAuthValidation() .AddOpenIdConnectServer(options => { options.AuthorizationEndpointPath = new PathString(AuthorizePath); // Enable the token endpoint. options.TokenEndpointPath = new PathString(TokenPath); options.ApplicationCanDisplayErrors = true; options.AccessTokenLifetime = TimeSpan.FromMinutes(5); #if DEBUG options.AllowInsecureHttp = true; #endif options.Provider.OnValidateAuthorizationRequest = context => { if (string.Equals(context.ClientId, Configuration["OpenIdServer:ClientId"], StringComparison.Ordinal)) { context.Validate(context.RedirectUri); } return Task.CompletedTask; }; // Implement OnValidateTokenRequest to support flows using the token endpoint. options.Provider.OnValidateTokenRequest = context => { // Reject token requests that don't use grant_type=password or grant_type=refresh_token. if (!context.Request.IsClientCredentialsGrantType() && !context.Request.IsPasswordGrantType() && !context.Request.IsRefreshTokenGrantType()) { context.Reject( error: OpenIdConnectConstants.Errors.UnsupportedGrantType, description: "Only grant_type=password and refresh_token " + "requests are accepted by this server."); return Task.CompletedTask; } if (string.IsNullOrEmpty(context.ClientId)) { context.Skip(); return Task.CompletedTask; } if (string.Equals(context.ClientId, Configuration["OpenIdServer:ClientId"], StringComparison.Ordinal) && string.Equals(context.ClientSecret, Configuration["OpenIdServer:ClientSecret"], StringComparison.Ordinal)) { context.Validate(); } return Task.CompletedTask; }; // Implement OnHandleTokenRequest to support token requests. options.Provider.OnHandleTokenRequest = context => { // Only handle grant_type=password token requests and let // the OpenID Connect server handle the other grant types. if (context.Request.IsClientCredentialsGrantType() || context.Request.IsPasswordGrantType()) { //var identity = new ClaimsIdentity(context.Scheme.Name, // OpenIdConnectConstants.Claims.Name, // OpenIdConnectConstants.Claims.Role); ClaimsIdentity identity = null; if (context.Request.IsClientCredentialsGrantType()) { identity = new ClaimsIdentity(new GenericIdentity(context.Request.ClientId, "Bearer"), context.Request.GetScopes().Select(x => new Claim("urn:oauth:scope", x))); } else if (context.Request.IsPasswordGrantType()) { identity = new ClaimsIdentity(new GenericIdentity(context.Request.Username, "Bearer"), context.Request.GetScopes().Select(x => new Claim("urn:oauth:scope", x))); } // Add the mandatory subject/user identifier claim. // By default, claims are not serialized in the access/identity tokens. // Use the overload taking a "destinations" parameter to make sure // your claims are correctly inserted in the appropriate tokens. identity.AddClaim(OpenIdConnectConstants.Claims.Subject, Guid.NewGuid().ToString("n") + Guid.NewGuid().ToString("n"), OpenIdConnectConstants.Destinations.AccessToken, OpenIdConnectConstants.Destinations.IdentityToken); var ticket = new Microsoft.AspNetCore.Authentication.AuthenticationTicket( new ClaimsPrincipal(identity), new Microsoft.AspNetCore.Authentication.AuthenticationProperties(), context.Scheme.Name); // Call SetScopes with the list of scopes you want to grant // (specify offline_access to issue a refresh token). ticket.SetScopes( OpenIdConnectConstants.Scopes.Profile, OpenIdConnectConstants.Scopes.OfflineAccess); context.Validate(ticket); } return Task.CompletedTask; }; 现在我得到的错误是: InvalidOperationException:没有注册任何身份验证处理程序 “Cookies”计划。注册方案有:申请、承载、 ASOS。你是否忘记打电话 AddAuthentication().AddSomeAuthHandler? 我在这里缺少什么。有什么帮助吗? 所以发现了问题,实际上我在 cookie 方案中使用“应用程序”名称,而在控制器中我使用默认名称“Cookies”。因此只需将显式的“应用程序”名称删除为默认的“Cookies”名称 未指定authenticationScheme,且未找到DefaultChallengeScheme Cookies Authentication 就我而言,我在添加身份验证时使用“Cookie”,在调用 SiginOut 方法时使用“Cookie”。 更改了两个使用“Cookies”的地方 启动: services.AddAuthentication(config => { config.DefaultScheme = "Cookies"; config.DefaultChallengeScheme = "oidc"; }) .AddCookie("Cookies")<---- Change here. .AddOpenIdConnect("oidc", config => { config.Authority = "https://localhost:44392/"; config.ClientId = "client_id_mvc"; config.ClientSecret = "client_secret_mvc"; config.SaveTokens = true; config.ResponseType = "code"; //config.SignedOutCallbackPath = "/Privacy"; }); 呼叫退出: public async Task<IActionResult> OnPostAsync() { return SignOut("Cookies", "oidc"); }
在asp.net core 2.0中使用identityserver4时出现无限身份验证循环
我有一个使用identityserver4框架的身份服务器,它的url是http://localhost:9000 我的Web应用程序是asp.net core 2.0,它的url是http://localhost:60002。该应用程序将使用...
Entity Framework Core 2.0:如何配置一次抽象基类
我有一个基本模型: 公共抽象类状态 { 公共字符串 updateUserName { 获取;放; } } 然后是扩展上面定义的基本模型的模型: 公开课项目:状态 { p...
在 ASP.NET Core 2 应用程序中,我设置了一些服务: 公共无效ConfigureServices(IServiceCollection服务) { services.AddDbContext(选项=> 选项。
是否可以禁用.NET Core ConsoleLogger和DebugLogger中的类别输出?
我正在使用一个非常典型的(我认为)设置来登录我正在编写的 .NET Core 控制台应用程序: services.AddLogging(loggingBuilder => { loggingBuilder.AddConfiguration(Configuration.GetSection("
实体框架 - 对象“PK_AspNetUserTokens”依赖于列“UserId”
我在VS 2017(版本15.5)中创建了一个新的ASP.NET Core 2 MVC项目,将用户id类型从字符串更改为Guid(还将ApplicationUser类名更改为User),添加我的模型,然后 添加-Migra...
我在运行时生成一个单例 公共无效ConfigureServices(IServiceCollection服务) { var applications = Utils.generateApplications() services.AddSingleton(
我最近将我的应用程序从“.NET Core2.2”迁移到“.NET 6”,并将 C# 语言从 C#8 升级到 C#10。 该应用程序使用 SQL Server,它首先基于数据库。 迁移后...
我知道它位于 HttpContext.Request.PathBase 中,但是在我拥有任何 HttpContext(在 Startup.cs 中)之前,我需要它来配置我的 cookie。 我的问题: 当 devops 配置应用程序时,他们 ...
C# API 上正文数据长度大于 100MB 的 HTTP 请求错误 500
我们在 C# 中开发了一个 ASP.NET Core 2.0 Web API,通过 Visual Studio 模板创建。 它已经运行多年,我们从未遇到过任何性能问题。直到最近,我们还没有...
如何使用 Entity Framework Core 2.1 定义多字段索引
我正在使用 ASP.Net Core 2.1 API,我使用 Entity Framework Core 2.1。我正在使用迁移来管理对数据库的更改。我的后备数据存储是 Azure SQL Server 的一个实例。 我...
既然 appsettings.json 就足够了,那么 hosting.json 有什么意义
在 .NET Core 2 Web API 应用程序中,我可以使用 appsettings.json 覆盖配置 url,但在官方文档中他们引入了额外的文件“hosting.json”,为什么?添加复杂性有什么意义...
为什么 asp.net core 应用程序不能在端口 4200 上运行?
我尝试从端口 4200 在 aspnet 核心应用程序中运行 launchsettings.json 文件,但是该站点会连续无声地失败,但是如果我使用不同的端口(如 5000),它将工作。为什么...
使用LINQ和Entity Framework在一个SQL查询中从多个表格中提取数据。
嗨,伙计们,我试图从多个表的数据拉在一个SQL查询使用LINQ和实体框架。我需要从数据库中获得的细节。我参考了这个如何过滤JSON数组中......
使用LINQ和Entity Framework在一个SQL查询中从多个表格中提取数据。
嗨,伙计们,我试图从多个表的数据拉在一个SQL查询使用LINQ和实体框架。我需要从数据库中获得的细节。我参考了这个如何过滤JSON数组中......