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 publ

Mendenzon Tatis Rosario 20 Reputation points
2024-03-20T06:22:03.5833333+00:00

This happened before with another application of mine which I was able to fix by removing the use redirect. However, this time it seems to be more complex, I am using dotNet 7 for the application and React for the front end all my checks are successful on github actions but the internal server error persists with the Spa not finding the indix.html. I also tried using the useFallBack(index.html) but the error persist.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,118 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
291 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
750 questions
{count} votes

Accepted answer
  1. JasonPan - MSFT 4,201 Reputation points Microsoft Vendor
    2024-03-20T08:28:09.8433333+00:00

    Hi @Mendenzon Tatis Rosario,

    For SPA projects, usually the front-end project is Angular/React/Vue, and the back-end project is ASP.NET Core API.

    Therefore, in the ASP.NET Core API, you need to use app.UseSpa or UseStaticFiles to allow static resource files to be read, and then the front-end project of the SPA needs to be included in the compilation process. This ensures that the index.html file can be found using useFallBack as an entry.

    Sample settings

      <ItemGroup>
        <!-- Don't publish the SPA source files, but do show them in the project files list -->
        <Content Remove="$(SpaRoot)**" />
        <None Remove="$(SpaRoot)**" />
        <None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
    
        <Content Include="ClientApp\dist\**">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
      </ItemGroup>
    
    

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Jason

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful