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

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.