3

I have a React website connected to Asp.net MVC webapi2. they are on two domain and it makes cross domain problems. How can I have them on the same domain?

IIS6 Asp.net 4.5

MESepehr
  • 758
  • 6
  • 19

2 Answers2

2

I think you can create a site and a virtual directory. In the virtual directory you can deploy the apis.

So for example if your domain is www.yourdomain.com, this site points to the react application.

and you can create www.yourdomain.com/apis (Virtual folder) where you can deploy all the apis project.

aepelman
  • 311
  • 2
  • 12
  • I tried this approach, but reactjs site in www.yourdomain.com treats www.yourdomain.com/apis as part of the reactjs site. It doesn't work as the .net core api. Any help is appreciated. Thanks – Asela May 13 '21 at 14:34
0

Solution 1: Host Both in Different Folders in Same Server, and Use Same Domain.

Solution 2:

If its Cross-Origin Resource Sharing Problem. Then Enable CORS in your WebApi Project.

In API Controller:

    [EnableCors(origins: "http://myreactclient.domain.com", headers: "*", methods: "*")]
    public class TestController : ApiController
    {

    }

Check this or this Post to know how to enable it.

Shaiju T
  • 6,201
  • 20
  • 104
  • 196