MVC Web API: No 'Access-Control-Allow-Origin' Header Is Present on the Requested Resource

.NET 6 Web Api Project No 'Access-Control-Allow-Origin' header is present on the requested resource

Thanks to @TinyWang :

I added

<DockerfileRunArguments>-e "ENABLE_CORS=true" -p 81:80</DockerfileRunArguments>

inside of my .csproj.

Now i'm able to call my web server (192.168.2.157:81) form my client (127.0.0.1)

Why I get No 'Access-Control-Allow-Origin'?

The message is clear:

No 'Access-Control-Allow-Origin' header is present on the requested resource

So, you are doing a cross origin request; i.e.: form https://example1.com:someotherport to https://example2.com:someport, and it is blocked by the browser due to the missing header.

The error occurs if:

  1. CORS is not configured
  2. CORS is configured, but due to an internal server error or such, the header is not appended.

Note: if you believe you did '1', most likely it's '2'

Have a look at this MSDN documentation to resolve it: https://learn.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-5.0

No 'Access-Control-Allow-Origin' error when accessing web-api from angular2

You need to enable CORS (cross origin request) in your web api. Follow instruction given in below page

https://learn.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api

No 'Access-Control-Allow-Origin' header is present on the requested resource from Azure App Service API

The issue was that even though CORS was enabled in the application code, there is also a CORS page in the Azure portal where a list of origins must be added.

To find it just Search for 'CORS' in the Azure portal search bar and add the URL of the site that you would like to have access to your endpoints.

No 'Access-Control-Allow-Origin' header is present on the requested resource Asp.Net Web Api Owin and Angular 8

It has been solved by removing context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] {"*"}); code from GrantResourceOwnerCredentials method.

And also I changed runtime order of app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); code before ConfigureOAuthTokenGeneration(app) code at Startup.cs

No 'Access-Control-Allow-Origin' header is present on the requested resource in web api

Remove the space between web methods in the CORS attribute

[EnableCors("*", "*", "PUT,POST")]


Related Topics



Leave a reply



Submit