.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:
- CORS is not configured
- 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
Mvvm in Wpf - How to Alert Viewmodel of Changes in Model... or Should I
Programmatically Add an Application to Windows Firewall
How to Use Interface as a C# Generic Type Constraint
ASP.NET Identity Get All Roles of Logged in User
Xmlwriter to Write to a String Instead of to a File
Enumerate Windows Like Alt-Tab Does
Custom Attribute on Property - Getting Type and Value of Attributed Property
Why Can't I Catch an Exception from Async Code
Create a Coroutine to Fade Out Different Types of Object
Display a Image in a Console Application
How to Check If Any Flags of a Flag Combination Are Set
How to Specify a Generic Type in Xaml (Pre .Net 4 Framework)
Is There a Way of Setting a Property Once Only in C#
Struct Constructor: "Fields Must Be Fully Assigned Before Control Is Returned to the Caller."