Tutorial: Create an ASP.NET Core app with React in Visual Studio - on IIS - error 404

dtk 1 Reputation point
2022-08-28T14:06:14.543+00:00

I built and published the application using this instruction: https://learn.microsoft.com/en-us/visualstudio/javascript/tutorial-asp-net-core-with-react?view=vs-2022 I used two projects: "Standalone JavaScript React" and "ASP.NET Core Web API" Visual Studio templates.

Chose publish ASP.NET Core project to the folder. Moved the application to a local IIS server and created a website. Before publishing, I corrected the URL of the 'target' parameter to React to the URL of the website. Perhaps there is a wrong action here.

As a result,

"http://localhost" response with code 404
"http://localhost/weatherforecast" response 200 with JSON

How to configure the application to run on the IIS server?

Internet Information Services
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,165 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,021 Reputation points
    2022-08-30T01:52:57.363+00:00

    It appears you want the webapi site to host the react app. Be sure the webapi app has the static file handler. Deploy the react app publish folder to wwwroot folder in the webapi site.

    Note: there is a webapi react template that you can use for a combined project.


  2. Bruce (SqlWork.com) 56,021 Reputation points
    2022-08-31T15:26:23.567+00:00

    the publish folder does not look correct. your index.html is at https://localhost/static/index.html

    the static folder should only have /css and /js, the rest of the files should in wwwroot folder (site root).

    if you look in index.html, it references the css and js files with /static/css/...

    note: in dev mode, the react site is the website and proxies to the webapi project. when published, the webapi site uses the static file handler to host the react files.


  3. Bruce (SqlWork.com) 56,021 Reputation points
    2022-09-01T15:17:00.447+00:00

    if

    https://localhost/index.html

    does not work, then IIS is not serving the static files. use IIS manager and view content. the index.html should be at the root. maybe the permissions are wrong. check that the anonymous user has access to the folder. you could also add the static file handler to the webapi project.

    0 comments No comments