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.

CORS for Core project

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
hikalkancommented, Oct 20, 2016

That shows other middlewares also need it (probably authorization middlewares). It was not well defined in ASP.NET Core docs.

1reaction
gabrielrobertcommented, Oct 19, 2016

It’s working 👍 . We need to put it just after “UseAbp”. Just before “AddMvc” in my case didn’t worked.

Read more comments on GitHub >

github_iconTop 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 >

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