【发布时间】:2020-08-27 14:34:52
【问题描述】:
我已尝试将所有方法调用移动不少于 10,000 次。我需要尝试第 10,001 次才能成为获胜者! 我做错了什么?
我不断收到与 CORS 相关的错误,但我已按照指南尝试解决它。
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddDefaultPolicy(
builder =>
{
builder.WithOrigins("http://localhost:3000").AllowAnyHeader().AllowAnyMethod();
});
});
//services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
services.AddControllers();
services.AddAuthentication(IISDefaults.AuthenticationScheme);
services.AddSwaggerGen();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "MES vs API");
});
app.UseHttpsRedirection();
app.UseRouting();
app.UseCors("AllowAnyOrigin");
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
在反应中,我有这个:
fetch('http://localhost:44387/api/Users/GetTest').then(function (response) {
this.state.user = response.text();
});
【问题讨论】:
-
我已经设法让客户端上的 API 调用保持在(待定)状态。所以有…………那个……
-
请在您的 React 应用中打开开发控制台并检查控制台“网络”选项卡下的 HTTP 调用。在特定调用中,响应标头中存在“Access-Control-Allow-Origin”标头?
-
直到我在 Startup.cs 中搞砸了——导致我发布了代码。现在它一直处于挂起状态,然后最终失败,并在 F12 中出现 CONNECTION_RESET 错误。这需要几分钟时间。
-
app.UseHttpsRedirection();把它移过来 -
把它移过来?去哪里?
标签: c# reactjs asp.net-core cors