-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Enabling CORS - How To Fix Cors Policy Issue? #467
Comments
Hi, I hope the following settings will help you. ConfigureServices: Configure: these settings must be between routing and authentication. app.UseCors(x => x app.UseAuthentication(); Have a nice coding 😊 |
Hello @iayti, Thanks for the input. So I just did exact same thing but the issue still persist with the CORS policy issue when using a new Angular front end. But i'm able to access the end points with Postman. Please see below the configure method; And the Cors policy issue error; Any other idea on how to fix will be appreciated. Thanks |
Try these variants:
In Configure
|
Hello @ramax495 , Thanks alot for the help. I see you edited your comment. The initial solution fix the issue. See below changes i made;
Then, the last code did the trick in Configure as well;
Once again, thanks! |
I think the key is |
Yea, changing the location of But i noticed that if i didnt put |
It's optional way. In one case you add your configured named policy in In other case you add your named policy manually to each endpoint using In one more case you can just configure default policy using But all in all nothing of this works if you call |
Thanks alot for the explanation. I just looked at my previous project and I noticed I commented Mind to explain briefly why we call |
@ngajugodwin Soryy, but I dont't know the reason. There is related issue in dotnet repo: dotnet/AspNetCore.Docs#19957 |
Interestingly this is a known issue already. Now you mention it on their repo, hopefully MS look into the issue because this can sometime be confusing. |
@ngajugodwin |
Thanks. I'll just read through just now. Waseem explanation did the justice. Now I understand what is going on behind the scene. Much appreciated for the pointed and your time. |
Thanks all |
Hello,
How do I enable CORS. I'm currently trying to connect my Angular to the backEnd but still hitting the CORS policy issue.
I currently have the below code under ConfigureService() method in the startup file.
services.AddCors(opt => { opt.AddPolicy("CorsPolicy", policy => { policy.AllowAnyHeader().AllowAnyMethod().WithOrigins("http://localhost:4200").Build(); }); });
And the below code under Configure() on same startup file.
app.UseCors("CorsPolicy");
Even after doing this, I still run into CORS policy issue.
Please, am I missing out something?
Appreciate any help.
The text was updated successfully, but these errors were encountered: