Base solution for your next web application
Open Closed

Unable to assign value to access-control-allow-headers #2875


User avatar
0
swapsword created

Hi,

We are using ABP template (ASP.NET core 1.x + angular 2) and we are trying to set the configuration CORS values (access-control-allow-headers value to "*") for node.js server (frontend Angular 2) which is starting the web server with url [http://localhost:4200]). As, we want to access this url from other host, however getting the error.

It is quiet straight forward for configure CORS for angular2 UI in ABP template inside StartUp.cs file. Below is the code from startup.cs.

//Configure CORS for angular2 UI
            services.AddCors(options =>
            {
                options.AddPolicy(DefaultCorsPolicyName, p =>
                {
                    //todo: Get from confiuration
                    p.WithOrigins("http://localhost:4200").AllowAnyHeader().AllowAnyMethod();
                });
            });

However, we are unable to find node server.js file inside the ABP where we can set the access-control-allow-headers. CORS for Express Js example: [https://enable-cors.org/server_expressjs.html])

Or is there any other way of doing it in ABP?

Please check the error snapshot as attachment. [attachment=1:5ytxigwx]error.PNG[/attachment:5ytxigwx] [attachment=0:5ytxigwx]header.PNG[/attachment:5ytxigwx]


2 Answer(s)
  • User Avatar
    0
    swapsword created

    Hi All,

    Found out a way around. I solve by exporting the project using "ng build" command. This created and store project files into "dist" folder. "dist" folder is use for deployment. I copy this folder and hosted on IIS web server where I have Web.Config file. In this Web.Config we can set the CORS.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Thanks for sharing your solution.