-1

I'm building a website in Angular 4.
My url server side (Web Api) was http://localhost:55499/api My url client side is http://localhost:4200.
And it worked well.
For various reasons I changed the url server to http://localhost/AAA/api/ and I start to use iis express instead local iis.
And since then it has stopped working.
Brings the following error:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.

The response had HTTP status code 400.

I have in my response Access-Control-Allow-Origin:http://localhost:4200

I have in the controller:

[EnableCors(origins: "http://localhost:4200", headers: " * ", methods: " * ")]

I use IIS EXPRESS.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Tzof
  • 193
  • 12
  • I would recommend not using `"*"` it's only working for the config. It should be like `Headers: POST, GET, OPTIONS` and same for methods. – Swoox Mar 12 '18 at 10:39

2 Answers2

0

You should specify the headers and methods you want to allow. You just have two empty strings for both.

Norbert Bicsi
  • 1,562
  • 2
  • 19
  • 33
  • ho, Im sorry, I dont know why but the "*"has been dropped.i have this line [EnableCors(origins: "http://localhost:4200", headers: "*", methods: "*")] – Tzof Mar 12 '18 at 08:39
0

This is basically the domain access issue you are on different domain trying to access the data or resource on different domain.

If you are using node_modules the install cors module. and use it in your server app as follows

var express = require('express')
var cors = require('cors')
var app = express()

app.use(cors())

or you can enable this for single a route as well as follows.

 var express = require('express')
    var cors = require('cors')
    var app = express()
    app.get('/products/:id', cors(), function (req, res, next) {
      res.json({msg: 'This is CORS-enabled for a Single Route'})
    })

And Also refer stack answer by apsillers

Neha Tawar
  • 687
  • 7
  • 23