2

I'm trying to setup my local development environment for an angular application. I have the following projects:

  1. .NET Web API project that is hosted on a separate website (let's say localhost:81)

  2. MVC project with angular components hosted on default web site (localhost)

I want to use API from my angular app, however right now I need to deal with CORS requests as API is hosted on different web site. I want to avoid it.

I want to setup and endpoint for my MVC site (localhost/api) that is the proxy to API web site.

How can I do this using IIS?

URL rewrite module is not suited for such scenarios.

New Dev
  • 48,427
  • 12
  • 87
  • 129
lostaman
  • 922
  • 12
  • 25

1 Answers1

0

I hope this answers your question or points you in the right direction, I am also looking into this,

I used POSTMAN to test IIS web site to return something, for example

http://localhost/assets/json/config.json?=undefined

...I get the following header items: Postman GET API result without CORS

as you can see the CORS is missing,

  1. In the root directory which IIS web site points at (i.e. wwwroot) create if one does not exist yet
    web.config
    file and in it add the following

Adding web.config file to IIS web app root directory

web.config

  1. now run same thing with postman again and you should see CORS appearing

Postman GET API result with CORS

source: https://enable-cors.org/server_iis7.html

JaHeretyk
  • 1
  • 1