I need to access localhost:5002/api/login through localhost:9000.
I have tried almost all the solutions available online. But I keep getting the following error.
How to present the 'Access-Control-Allow-Origin' on the requested resource.
XMLHttpRequest cannot load localhost:5002/api/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:9000' is therefore not allowed access.
I have tried adding this to the Web.config
<httpProtocol> <customHeaders> <clear /> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol>
And In the server side StartUp.cs File I have added the following as well
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
});
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IUowProvider uowProvider)
{
app.UseCors("CorsPolicy");
app.UseMvc();
}