Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在web api.net core上获取cors类型的响应_C#_Asp.net_.net_Asp.net Core Webapi - Fatal编程技术网

C# 在web api.net core上获取cors类型的响应

C# 在web api.net core上获取cors类型的响应,c#,asp.net,.net,asp.net-core-webapi,C#,Asp.net,.net,Asp.net Core Webapi,我只是想返回一个url到一个客户端,我已经完成了cors策略的所有配置,但是我收到的唯一返回是cors类型的,没有任何我想要返回的url的信号,飞行前请求工作正常,请求本身也正常,返回api是我的问题 这是我的startup.cs public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration;

我只是想返回一个url到一个客户端,我已经完成了cors策略的所有配置,但是我收到的唯一返回是cors类型的,没有任何我想要返回的url的信号,飞行前请求工作正常,请求本身也正常,返回api是我的问题

这是我的startup.cs

 public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {

            services.AddTransient<ITokenManager, TokenManager>();
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton<IAccountService, AccountService>();
            services.AddSingleton<ITableauService, TableauService>();


            services.AddCors(options =>
            {
                options.AddPolicy("AllowAll",
                    builder =>
                    {
                        builder
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .Build();

                    });
            });

            services.Configure<MvcOptions>(options =>
            {
                options.Filters.Add(new CorsAuthorizationFilterFactory("AllowAll"));
            });

            services.AddMvc();

        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {

            app.UseAuthentication();
            app.UseCors("AllowAll");
            app.UseMvc();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }
        }
    }

现在我的客户机中的网络


提前谢谢,我会回复任何帮助。

响应类型为
cors
意思

从有效的跨来源请求收到响应。可以访问某些标题和正文

因此,只需使用以下方法获取返回的数据:

.then(response => {
  response.json().then((data) => {
      console.log(data);
    })
  }
)
此外,如果要返回url,应添加双引号,例如:

return Content("\"https://localhost:8080\"");

在“网络”选项卡中,是否检查了API调用的响应主体?另外,共享呼叫的客户端代码?如果您正在使用
jquery.ajax
尝试设置
数据类型:“text”
好的,我将用请求示例更新问题,我使用fetch api,谢谢您的时间
return Content("\"https://localhost:8080\"");