skip to Main Content

I have a reactjs app that has controllers written in c#. I have a c# service that makes a call to the controller via the following syntax

const getUserDetails = (userId) => {
  return data_post('user/GetUser/' + userId, {})
}

That in turn calls my controller which is a c# file residing in a directory Controller under ClientApp and it returns the data to the js file in the ClientApp directory.

Now when I want to start my React app, I do so via the following:

npm start

But the issue is when i try to call any of these it says that the controller is not recognized. that is how can i start the react front end and the .net web API backend?

I have tried running the app using npm start –prefix .ClientApp , still didn’t work.

How can I start the app and make sure that the API/controllers are loaded?

2

Answers


  1. Well, you need to first ensure that your C# backend is running…

    The 404 status code for user/GetUser endpoint indicates that there is no such endpoint.

    It’s true since you’re not running the backend.

    Depending on the complexity of your app you should figure out what classes to run BUT the basic terminal command for compiling C# is "csc myClass.cs" and then "./myClass.exe" to execute the compiled solution.

    Login or Signup to reply.
  2. npm start only run the react front-end. Your back-end api doesn’t run so it cannot be recognized.
    If the webapi hasn’t been published yet, you should have a ".csproj" file. In the same directory just use dotnet run in the CMD will run that api.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search