Search code examples
azureasp.net-core

Publishing .NET Core React projects to Azure


I am using Visual Studio template called "React with ASP.NET Core". This template has 2 different projects, one for backend which includes ASP.NET Core Web API controllers etc., and the other client side stuff such as react.

When I run or debug project, it takes me to home controller. But actual interface of my home page which I created in react runs with npm command on localhost:3000. When I try to publish this project on Azure, it shows project has published successfully but when site opens, it says page not found with http 404 error.

I have another question: will the index.html be the entry point of the published project automatically? Since I open it through npm-start command? Do I need to publish them separately?

I can see in solution of this template the project reference of clientApp project has attached to backend project. And when publishing, npm build command is run.


Solution

  • The 404 error might be due to incorrect configurations or missing files. In a typical React application, index.html is the entry point. However, in a mixed ASP.NET Core and React application, the entry point might depend on your project configurations but most of the time it is index.html. Yes, if your React and ASP.NET Core projects are separate, you may need to publish them separately. also make sure that the React app's static files are correctly included in the ASP.NET Core project.

    Hope this helps