CORS for Core project
See original GitHub issueI’m trying to call APP service API from another application. I put these in my Startup.cs:
public IServiceProvider ConfigureServices(IServiceCollection services)
{
//CORS
var corsBuilder = new CorsPolicyBuilder();
corsBuilder.AllowAnyHeader();
corsBuilder.AllowAnyMethod();
corsBuilder.AllowAnyOrigin();
corsBuilder.AllowCredentials();
services.AddCors(options =>
{
options.AddPolicy("AllowAll", corsBuilder.Build());
});
// MVC
services.AddMvc(options =>
{
options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
});
//Configure Abp and Dependency Injection
return services.AddAbp<TemplWebModule>(options =>
{
//Configure Log4Net logging
options.IocManager.IocContainer.AddFacility<LoggingFacility>(
f => f.UseAbpLog4Net().WithConfig("log4net.config")
);
});
}
public void Configure(IApplicationBuilder app)
{
app.UseAbp();
AuthConfigurer.Configure(app, _appConfiguration);
app.UseStaticFiles();
app.UseAppBuilder(ConfigureOwinServices);
app.UseCors("AllowAll");
app.UseMvc(routes =>
{
routes.MapRoute(
name: "defaultWithArea",
template: "{area}/{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
I still have this issue:
XMLHttpRequest cannot load http://localhost:5102/api/services/app/Test/Get?id=9b1576ac-8be9-4f05-24e4-08d3eeaf7b71. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://testproject.local' is therefore not allowed access. The response had HTTP status code 500.
I even tried to put this on my application service interface:
[EnableCors("AllowAll")]
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (8 by maintainers)
Top Results From Across the Web
Enable Cross-Origin Requests (CORS) in ASP.NET Core
Learn how CORS as a standard for allowing or rejecting cross-origin requests in an ASP.NET Core app.
Read more >Enabling Cross-Origin Requests in ASP.NET Web API 2
Using CORS, a server can explicitly allow some cross-origin requests while rejecting others. CORS is safer and more flexible than earlier ...
Read more >How to enable cors in ASP.NET Core 6.0 Web API project?
Configured CORS in my ASP.NET Core 6.0 Web API project. But the preflight request receives a http 405 error. In other words HTTP...
Read more >Enabling CORS in ASP.NET Core By Example
Let's learn about enabling CORS in ASP.NET Core, what is the Same Origin Policy and how CORS works with different policies.
Read more >CORS (3), Enable CORS In .NET Core Web API
This is an article following Consume Web API By MVC In .NET Core (3), to enable CORS to make an access from Cross...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That shows other middlewares also need it (probably authorization middlewares). It was not well defined in ASP.NET Core docs.
It’s working 👍 . We need to put it just after “UseAbp”. Just before “AddMvc” in my case didn’t worked.