amo*_*mol 8 asp.net-web-api2 asp.net-core-mvc identityserver3 asp.net-core angular
我正在使用ASP.NET 5,在我的解决方案中我有Web API,Identity Server和Angular 2项目,我使用Identity Server验证Angular 2客户端,Angular 2客户端通过在http请求中传递令牌和web api身份验证来使用web api令牌并给出响应,为此我编写了一个自定义属性,用于检查用户是否经过身份验证
当我使用API时,我遇到异常,Web API返回500内部服务器错误.
System.InvalidOperationException:IDX10803:无法从以下位置获取配置:' http://xx.xx.xx.x:3926/.well-known/openid-configuration '.---> System.IO.IOException:IDX10804:无法从以下位置检索文档:' http://xx.xx.xx.x:3926/.well-known/openid-configuration '.---> System.AggregateException:发生一个或多个错误.---> System.Net.Http.HttpRequestException:发送请求时发生错误.---> System.Net.WebException:无法连接到远程服务器---> System.Net.Sockets.SocketException:连接尝试失败,因为连接方在一段时间后没有正确响应,或建立连接失败,因为连接的主机无法在System.Net.Service.ConnectSocketInternal的System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)上响应xx.xx.xx.x:3926(布尔connectFailure,Socket s4,Socket s6,Socket&套接字,IP地址和地址,ConnectSocketState状态,IAsyncResult asyncResult,异常和异常)
lea*_*ege 13
如果identityserver和访问令牌验证中间件托管在同一个应用程序中,则启动时会出现竞争条件.
验证中间件尝试加载尚未提供的发现文档.
在这些方案中,将DelayLoadMetadata验证中间件上的标志设置为true.
如果完全禁用发现端点,则需要在验证选项上配置颁发者和密钥材料.
此错误的原因是代理,并且能够通过实现以下代码来解决它:
options.BackchannelHttpHandler = new HttpClientHandler()
{
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator,
Proxy = new WebProxy(Configuration["System:Proxy"])
};
Run Code Online (Sandbox Code Playgroud)
如果您收到“无法从以下位置检索文档:'[pii is hide]'”,您需要将以下内容添加到ConfigureServices:
public void ConfigureServices(IServiceCollection services)
{
......
IdentityModelEventSource.ShowPII = true;
}
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助。
我使用了类似的方法,它解决了我的问题。
services.AddAuthentication(o => {
o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddCookie(cfg => cfg.SlidingExpiration = true)
.AddJwtBearer(cfg =>
{
cfg.Audience = "http://localhost:4200/";
cfg.Authority = "http://localhost:5000/";
cfg.RequireHttpsMetadata = false;
cfg.SaveToken = true;
cfg.TokenValidationParameters = tokenValidationParameters;
cfg.Configuration = new OpenIdConnectConfiguration(); <-- Most IMP Part
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14308 次 |
| 最近记录: |