使用IdentityModel执行GET时,我得到以下错误DiscoveryClient,如下所示:
var discoveryResponse = await DiscoveryClient.GetAsync("https://localhost/IdentityServer");
Run Code Online (Sandbox Code Playgroud)
颁发者名称与权限不匹配:https:// localhost/identityserver
目标URL是在使用IdentityServer4启用的IIS上运行的ASP.NET Core Web应用程序.客户端应用程序是在同一台计算机上运行的经典ASP.NET Web应用程序.
显然,GET确实设法从IdentityServer检索值,如以下内容所示discoveryResponse.Raw:
{
"issuer": "https://localhost/identityserver",
"jwks_uri": "https://localhost/IdentityServer/.well-known/openid-configuration/jwks",
"authorization_endpoint": "https://localhost/IdentityServer/connect/authorize",
"token_endpoint": "https://localhost/IdentityServer/connect/token",
"userinfo_endpoint": "https://localhost/IdentityServer/connect/userinfo",
"end_session_endpoint": "https://localhost/IdentityServer/connect/endsession",
"check_session_iframe": "https://localhost/IdentityServer/connect/checksession",
"revocation_endpoint": "https://localhost/IdentityServer/connect/revocation",
"introspection_endpoint": "https://localhost/IdentityServer/connect/introspect",
"frontchannel_logout_supported": true,
"frontchannel_logout_session_supported": true,
"scopes_supported": [ "CustomIdentityResources", "profile", "openid", "MyAPI.full_access", "offline_access" ],
"claims_supported": [],
"grant_types_supported": [ "authorization_code", "client_credentials", "refresh_token", "implicit" ],
"response_types_supported": [ "code", "token", "id_token", "id_token token", "code id_token", "code token", "code id_token token" ],
"response_modes_supported": [ "form_post", "query", "fragment" ],
"token_endpoint_auth_methods_supported": …Run Code Online (Sandbox Code Playgroud) This article, https://devblogs.microsoft.com/aspnet/improvements-in-net-core-3-0-for-troubleshooting-and-monitoring-distributed-apps/, tells me that the field TraceId is available as a correlation id, which is great!
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
=> ConnectionId:0HLR1BR0PL1CH
=> RequestPath:/weatherforecastproxy
RequestId:0HLR1BR0PL1CH:00000001,
SpanId:|363a800a-4cf070ad93fe3bd8.,
TraceId:363a800a-4cf070ad93fe3bd8,
ParentId: Executed endpoint 'FrontEndApp.Controllers.WeatherForecastProxyController.Get
(FrontEndApp)'
Run Code Online (Sandbox Code Playgroud)
In fact, I can see that in our log sink this works as advertised: When web application A serves a request and in doing so invokes web application B, both of them write the same TraceId value to the log.
As far as I understand, any ASP.NET …
我在IIS中托管经典.NET WebAPI端点,该端点接受POST请求以上载文档.
我创建了两个连接到WebAPI并上传文档的控制台应用程序:一个是经典的.NET(v4.6.2)控制台应用程序,另一个是.NET Core控制台应用程序.代码是相同的,但服务对每个代码的响应不同.WebAPI似乎无法读取.NET Core POST请求的请求主体,但能够使用Classic .NET POST请求执行此操作.
有什么我想念的吗?
WebAPI端点
[Route("api/Documents")]
public class DocumentsController : ApiController
{
[HttpPost()]
public void Create([FromBody] Document document)
{
if (document == null)
{
Debug.WriteLine("Posted document is null.");
}
else
{
Debug.WriteLine($"Document text: {document.Text}");
}
}
}
public class Document
{
public string Text { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
.NET Core/Classic .NET控制台应用程序
class Program
{
static void Main(string[] args)
{
RunAsAsync().Wait();
}
static async Task RunAsAsync()
{
var httpClient …Run Code Online (Sandbox Code Playgroud) 我的启动中有以下设置:
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", true, true);
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true, true)
Run Code Online (Sandbox Code Playgroud)
appsettings.json:
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过添加具有不同值的匹配JSON结构来覆盖给定环境的有效设置,并省略我想要继承的那些,例如appsettings.Development.json:
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
Run Code Online (Sandbox Code Playgroud)
但是我可以删除条目或部分,除非用空值覆盖每个值属性吗?
-S
我想使用StructureMap ObjectFactory来处理我的WCF服务使用的类的实例化.虽然我有限的经验足以处理一个接口与实现它的单个类之间的简单1:1映射,但我遇到了构造函数接受同一接口的多个参数的障碍.
我认为通过为每个映射命名,我可以将多个具体类关联到同一个接口,但是如何告诉StructureMap用于第一个和第二个构造函数参数的映射?
这是我想要ObjectFactory为我处理的类:
public class MasterPolicy {
public MasterPolicy(IPolicy alfaPolicy, IPolicy numericPolicy)
{
AlphaPolicy = alphaPolicy;
NumericPolicy = numericPolicy;
}
public IPolicy AlphaPolicy {get; private set; }
public IPolicy NumericPolicy {get; private set; }
public bool IsValid(string s)
{
if (!AlphaPolicy.IsValid(s)) return false;
if (!NumericPolicy.IsValid(s)) return false;
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
IPolicy接口由多个类实现:
public interface IPolicy
{
bool IsValid(string s);
}
public class AlphaPolicy : IPolicy
{
public bool IsValid(string s) { return true; }
}
public class NumericPolicy : …Run Code Online (Sandbox Code Playgroud) 亲爱的互联网社区.
我需要将元素从一个对象映射到另一个对象.这些类是相同的(相同的类名,相同的属性),所以我认为我们应该尝试使用AutoMapper.它似乎工作得很好,但我遇到了障碍:一个类有一个object类型属性,用作一种"外卡"容器.
public class MyPet
{
public int Id { get; set; }
public object Pet{ get; set; }
}
public class Cat
{
}
public class Dog
{
}
Run Code Online (Sandbox Code Playgroud)
我初步认为AutoMapper能够识别实例的类型并按照指示执行适当的映射:
Mapper.CreateMap<LocalService.MyPet, ExternalService.MyPet>();
Mapper.CreateMap<LocalService.Cat, ExternalService.Cat>();
Mapper.CreateMap<LocalService.Dog, ExternalService.Dog>();
var dtoWithCat0 = new LocalService.MyPet()
{
Id = 1,
Item = new LocalService.Cat()
};
var dtoWithDog0 = new LocalService.MyPet()
{
Id = 2,
Item = new LocalService.Dog()
};
var dtoWithCat1 = Mapper.Map<ExternalService.MyPet>(dtoWithCat0);
var dtoWithDog1 = Mapper.Map<ExternalService.MyPet>(dtoWithDog0);
Console.WriteLine("{0}: {1} - {2}", dtoWithCat1.GetType().FullName, …Run Code Online (Sandbox Code Playgroud) 请考虑以下界面:
public interface IProvider
{
Task<bool> Contains(string key);
}
Run Code Online (Sandbox Code Playgroud)
这是实现满足Visual Studio
public Task<bool> Contains(string key)
{
return Task.FromResult(false);
}
Run Code Online (Sandbox Code Playgroud)
这种实现方便编写,似乎可以实现同样的目的:
public async Task<bool> Contains(string key)
{
return false;
}
Run Code Online (Sandbox Code Playgroud)
然而,Visual Studio引发了一种混乱并坚持:
这种异步方法缺少"等待"运算符并将同步运行.考虑使用'await'运算符等待非阻塞API调用,或'await TaskEx.Run(...)'在后台线程上执行CPU绑定工作.
我很乐意忽略这个警告并避免使用Task.FromResult(...).
使用后一种选择会产生任何负面影响吗?
我正在考虑构建一个实现 IdentityServerIResourceStore接口的类。我的目标是提供自定义存储库中定义的服务IdentityResource和ApiResource集合。
理想情况下,我将收到对这些资源的请求,并使用与查询相关的子集进行响应。简而言之:你只得到你所要求的。
这个GetAllResources()方法让我怀疑:IdentityServer 是否真的要求我从我的存储库中提取我的整个身份和 API 资源集并使其可用?在这一点上,我不知道这些集合会增长多大,或者从存储库中提取它们的成本。
简单地以空或空的资源列表响应会产生什么后果?
-S
asp.net-core ×3
.net-core ×2
c# ×2
.net ×1
appsettings ×1
asp.net ×1
async-await ×1
asynchronous ×1
automapper ×1
interface ×1
list ×1
structuremap ×1