相关疑难解决方法(0)

CORS 策略和 .NET Core 3.1 的问题

我不确定我错过了什么,但似乎无法让我的 CORS 策略与 .NET Core 3.1 和 Angular 8 客户端一起使用。

Startup.cs

        public void ConfigureServices(IServiceCollection services)
        {
            // ...

            // Add CORS policy
            services.AddCors(options =>
            {
                options.AddPolicy("foo",
                builder =>
                {
                    // Not a permanent solution, but just trying to isolate the problem
                    builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
                });
            });

            services.AddControllers();
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            // Use the CORS policy
            app.UseCors("foo");

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Run Code Online (Sandbox Code Playgroud)

错误消息客户端:

Access to XMLHttpRequest at 'https://localhost:8082/api/auth/' …
Run Code Online (Sandbox Code Playgroud)

cors .net-core angular

43
推荐指数
3
解决办法
3万
查看次数

标签 统计

.net-core ×1

angular ×1

cors ×1