Error after publishing asp web api core with react app compained on it

Doaa Ahmad Badwy 1 Reputation point
2022-09-22T14:43:05.68+00:00

Error after publishing asp web api core with react app complained on it I couldn't access it from browser and that error appears in the windows event log

Exception:
System.InvalidOperationException: The SPA default page middleware could not return the default page '/index.html' because it was not found, and no other middleware handled the request.
Your application is running in Production mode, so make sure it has been published, or that you have built your SPA manually. Alternatively, you may wish to switch to the Development environment.

even I could access my API from post man but I couldn't from browser

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,400 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 51,346 Reputation points
    2022-09-22T14:52:22.71+00:00

    FYI that error can happen even with a working app. We see it in our prod logs and it is something about how .NET Core's SPA middleware is working. Unless it is causing you actual issues I wouldn't worry about it. We haven't taken the time to figure it out yet because our app is still working fine and it has been this way for months.

    As for accessing the API I'm a little confused. You said you built an API app with React but React is a UI front end. APIs don't have front ends. I'm assuming this is a web app that uses React for the front end and .NET Core/6 for the backend. When you attempt to browse to the site you should get a response from the server with the relevant status code and message. What are you getting?

    I'm assuming you configured IIS properly for .NET Core as documented here. Specifically you installed the hosting bundle on your server, you set up the app pool correctly, permissions are correct and your app deployed fully.

    0 comments No comments

  2. Bruce (SqlWork.com) 61,731 Reputation points
    2022-09-22T20:24:17.203+00:00

    in production release, spa services is expecting production build of react. the publish folder should have a wwwroot folder which is deployed to IIS. so if you look at IIS site content, index.html should be at the site root. there should be a static folder at the root which has the react js files

    /index.html  
    /static  
       /js  -  *.js  
       /css - *.css  
    /<your webapi app name>.dll  
      
      
    

    other files as required

    note: in production, spa services is acting as a static file handler.

    0 comments No comments