I'm just trying to return a url to a client i already did all configuration of cors policy but the only return i recieve is of type cors, without any signal of the url that i want to return, the preflight request works fine and the request itself either, the return of my api its my problem.
this is my 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();
}
}
}
fetch api request from client
fetch('https://baseurl?folder=AcompanhamentoComparativoLocaliza&view=DashEmails'
, {
headers: new Headers({
'authorization': 'AuthToken',
'Content-Type':'application/json',
})
})
.then(response => {
console.log('teste',response)
}
)
.catch(error => console.error(error))
this is the output of cors policy, as you guys can see they are executed sucessfully
this is the return in my controller
and now the network in my client
preflight network headers and status
Thanks in advance, i apreaciate any help.
Response type is cors
means
Response was received from a valid cross-origin request. Certain headers and the body may be accessed.
So just get the returned data using :
.then(response => {
response.json().then((data) => {
console.log(data);
})
}
)
In addition , if you want to return url , you should add double quotes ,for example :
return Content("\"https://localhost:8080\"");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.