Access to fetch at *** from origin *** has been blocked by CORS policy: No 'Access-Control-Allow-Origin' Access to fetch at *** from origin *** has been blocked by CORS policy: No 'Access-Control-Allow-Origin' asp.net asp.net

Access to fetch at *** from origin *** has been blocked by CORS policy: No 'Access-Control-Allow-Origin'


i tried anerco's answer but it didn't work for me, i found this article, it has a very similar solution but with .SetIsOriginAllowed(origin => true) added and .AllowAnyOrigin() removed.

So you should add this code to your Configure method in startup class :

app.UseCors(x => x                    .AllowAnyMethod()                    .AllowAnyHeader()                    .SetIsOriginAllowed(origin => true) // allow any origin                    .AllowCredentials()); // allow credentials

I recommend reading the article to get a better understanding of all of this, it's very short and straight to the point.


Try this:

on Startup.cs => Confirgure add:     app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials());


Hi I'm new on this topic but because I've got this error last week I tried enabling options method and the first part resolved . This error happens due to policy and security issues but now I refer you to get the status code and in my case it was 405 error which means now we have to change our headers in the request to allow all methods and origins (no way )but it doesn't help me out.

So I figured out that I have enabled cookie encryption and session (wide of the point) in my app for my API therefore I disabled them and cleared browser cookie as well .

So try using these:

  1. Clear your cookies and add Access-Control-Allow-Origin': '*' by Mod Header extension and try again to check the fix .mod header - your header (client)

  2. Try using a middle interface to control your request and guide them into the special rules

    app.use((req, res, next) => {      res.header('Access-Control-Allow-Origin', '*');      next();    });

According to this site : https://medium.com/@dtkatz/3-ways-to-fix-the-cors-error-and-how-access-control-allow-origin-works-d97d55946d9