任务已取消 [英] A task was canceled

查看:96
本文介绍了任务已取消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在同一启动中共同托管Identityserver3和Web api(用于使用Bearer令牌的用户管理).但是我收到以下错误: 任务已取消. 似乎在尝试调用 http://identity_local/core/.well时,启动时发生了任务取消-known/openid-configuration (identity_local指向本地主机).

I am trying to co-host identityserver3 and web api (for user management using Bearer tokens) in the same startup. However I get the following error: A task was canceled. It appears the task cancellation occurs on startup when trying to call http://identity_local/core/.well-known/openid-configuration (identity_local points to localhost).

我的启动如下:

app.Map("/core", idsrvApp =>
        {
            var factory = new IdentityServerServiceFactory();
            factory.UserService = new IdentityServer3.Core.Configuration.Registration<IUserService, UserService>();
            factory.ScopeStore = new IdentityServer3.Core.Configuration.Registration<IScopeStore>(resolver => scopeStore);
            var options = new IdentityServerOptions
            {
                SigningCertificate = Certificate.Load(),
                IssuerUri = "http://identity_local/core",
                PublicOrigin = "http://identity_local",
                RequireSsl = false, //for now
                Factory = factory,
            };

            idsrvApp.UseIdentityServer(options);
        });

        app.Map("/admin", adminApp =>
        {
            adminApp.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority = "http://identity_local/core",
                IssuerName = "identity_local",
                ValidationMode = ValidationMode.Local,
                RequiredScopes = new[] { "api", "roles" }
            });

            adminApp.UseResourceAuthorization(new AuthorisationManager());

            var config = new HttpConfiguration();
            config.MapHttpAttributeRoutes();

            adminApp.UseCors(CorsOptions.AllowAll);
            adminApp.UseWebApi(config);

        });

有人知道a)是否可以在同一启动中同时运行b)如果是这样,我做错了什么或者我该怎么做才能解决上述问题.

Does anyone know if a) it is possible to have both in the same startup and b) if so, what have I done wrong or what can I do to remedy the above.

推荐答案

在启动时,UseIdentityServerBearerTokenAuthentication尝试联系IdentityServer元数据端点,但是由于服务器尚未运行,它无法连接,因此出现错误.

At startup time the UseIdentityServerBearerTokenAuthentication tries to contact the IdentityServer metatadata endpoint, but since the server is not yet running it can't connect, thus an error.

在这种情况下,有一个名为DelayLoadMetadata的标志将元数据的加载延迟到第一次需要时:

For this situation, there's a flag called DelayLoadMetadata to delay load the metadata until the first time it's needed: https://identityserver.github.io/Documentation/docsv2/consuming/options.html

这篇关于任务已取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆