siamak jalili
siamak jalili

Reputation: 53

Run Asp.net MVC and React on same domain

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

Upvotes: 3

Views: 1457

Answers (2)

Shaiju T
Shaiju T

Reputation: 6609

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.

Upvotes: 0

aepelman
aepelman

Reputation: 321

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.

Upvotes: 2

Related Questions