I have a web api on a IIS server using .Net Core 3.1.
It is using the IP and Port of: http://68.181.207.10:8473
I also have 3 web applications that run on the same IIS server. 2 of the apps are .Net 4.7 apps and 1 is a .Net Core app.
The 3 web apps all use the web api.
The 3 apps are:
https://meta.astro.usc.edu (port 443)
http://old.astro.perl.edu (port 80)
http://68.181.207.10 (port 80)
I have set up the API to use CORs, and for the most part, everything is ok and they connect to the API without any issues.
But there are times when I will still run into CORs errors even though I have added all the needed URLs.
In the top of my ConfigureServices method, I am adding the needed URLs that will need access, like this:
public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy(MyAllowSpecificOrigins, builder => { builder.WithOrigins("http://68.181.207.10:8473", "https://meta.astro.usc.edu", "http://old.astro.perl.edu", "http://68.181.207.10") .AllowAnyMethod() .AllowAnyHeader(); }); }); } Then in my Configure method, I am adding app.UseCors as you can see below:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseRouting(); app.UseCors(MyAllowSpecificOrigins); app.UseHttpsRedirection(); app.UseMvc(); } Is this the proper way of allowing these other web apps to connect to my web api?
The CORs errors seem random and the origins are always one of my 3 web apps. One doesn't seem to cause more errors than an another.
How can I prevent the intermittent CORs errors that I still receive?
Thanks!
The CORs errors seem random and the origins are always one of my 3 web apps. One doesn't seem to cause more errors than an another.. But you specify 4 sites inWithOrigins. I suspect there are http/https issues here. I also see thatapp.UseHttpsRedirection();comes beforeapp.UseCorsin doc, maybe have a look into that too.http://68.181.207.10:8473, which is the URL for the web api itself. I added that out of desperation...it didn't really seem to help anything though.