question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The server responded with a status of 405” + “Access to fetch… from origin … has been blocked by CORS policy

See original GitHub issue

Describe the bug

We have two different asp.net core web api applications employing the following C# code snippet.

public static IServiceCollection AddUniversalCORS(this IServiceCollection services)
            => services.AddCors(setupAction => setupAction.AddPolicy("myPolicy", builder =>
                builder
                    .AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()));

Also, we have an Angular app that calls both web apis. Making the call to the first web api goes through flawlessly and successfully but the 2nd one fails due to the following error message:

const url = ‘https://localhost:44317/api/logic/save’; const request = { method: ‘POST’, headers: { ‘Content-Type’: ‘application/json’, Authorization: Bearer ${this.authService.getToken()} }, body: JSON.stringify(this.myPayload) };

So, why one of the web api calls is successful but the other one fails due to the CORS error message? Really running out of reasons to justify this issue which made us get stuck for quite a while!

We also consulted StackOverflow to find an answer for this issue but none of the answers helped, unfortunately. As a side note, Submitting the same failed POST request in Angular by POSTMAN goes through successfully.

To Reproduce

Steps to reproduce the behavior:

  1. Using this version of ASP.NET Core 2.2

Expected behavior

The CORS should not fail and the angular app should be able to succeed in terms of placing the POST request.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
dcarr42commented, Jul 30, 2019

The operation is supported.

https://github.com/aspnet/AspNetCore/blob/master/src/Middleware/CORS/src/Infrastructure/CorsService.cs#L120

Just check the outgoing headers to see if anything else needs to be overridden.

0reactions
Arash-Sabetcommented, Jul 30, 2019

@DAllanCarr Not 100% following you. Any examples on your recent comment?

/cc @miladghafoori

Read more comments on GitHub >

github_iconTop Results From Across the Web

Access to fetch at *** from origin *** has been blocked by ...
This error happens due to policy and security issues but now I refer you to get the status code and in my case...
Read more >
The server responded with a status of 405” + “Access ...
The server responded with a status of 405” + “Access to fetch… from origin … has been blocked by CORS policy #12715.
Read more >
How to Fix the HTTP 405 Method Not Allowed Error
It's an HTTP response status code that indicates that the request method is known by the server but is not supported by the...
Read more >
405 Method Not Allowed: What It Is and How to Fix It
The 405 Method Not Allowed is an HTTP response status code indicating that the server received and recognized the specified request HTTP method ......
Read more >
Request to api from axios (cross domain) (CORS) error
Origin 'http://incomeaccounting.dev' is therefore not allowed access. The response had HTTP status code 405.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found