小编Dot*_*ver的帖子

无法加载http:// localhost:5000 / .known / openid-configuration:所请求的资源上不存在“ Access-Control-Allow-Origin”标头

我是Identityserver4的新手,最近我看到了Identityserver团队提供的Quickstart8示例,其中包括3个项目1.Identityserver 2.Api 3.Client在我部署到iis时,它们在浏览器中都运行良好工作正常,它显示错误,如...

在此处输入图片说明

我正在使用javascript客户端...

请帮我解决这个问题。

这是我的代码...

api(startup.cs)

using Microsoft.AspNetCore.Builder;
Run Code Online (Sandbox Code Playgroud)

使用Microsoft.Extensions.DependencyInjection;

名称空间Api {公共类Startup {公共无效ConfigureServices(IServiceCollection服务){services.AddMvcCore().AddAuthorization().AddJsonFormatters();

        services.AddAuthentication("Bearer")
            .AddIdentityServerAuthentication(options =>
            {
                options.Authority = "http://localhost:5000";
                options.RequireHttpsMetadata = false;

                options.ApiName = "api1";
            });

        services.AddCors(options =>
        {
            // this defines a CORS policy called "default"
            options.AddPolicy("default", policy =>
            {
                policy.WithOrigins("http://localhost:5003")
                    .AllowAnyHeader()
                    .AllowAnyMethod();
            });
        });
    }

    public void Configure(IApplicationBuilder app)
    {
        app.UseCors("default");

        app.UseAuthentication();

        app.UseMvc();
    }
}
Run Code Online (Sandbox Code Playgroud)

}

Api(身份控制器)

[Route("[controller]")]
[Authorize]
public class IdentityController : ControllerBase
{
    [HttpGet]
    public IActionResult Get()
    {
        return new JsonResult(from c in User.Claims select …
Run Code Online (Sandbox Code Playgroud)

c# cors asp.net-core identityserver4

5
推荐指数
1
解决办法
7233
查看次数

标签 统计

asp.net-core ×1

c# ×1

cors ×1

identityserver4 ×1