The SPA default page middleware could not return the default page '/index.html' in production application

See original GitHub issue

I have an ASP.Net Core / Angular 5 application that is logging errors to the Windows Event Log in our production environment. The following error is getting logged frequently but intermittently in production, and I have no idea why. The application is definitely in production mode, has been published, and is functioning.

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.

AFAIK no users are experiencing a problem with the site when these errors occur. Any idea why these errors are being thrown, and whether there is in fact a problem that needs to be addressed?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:36
  • Comments:103 (14 by maintainers)

github_iconTop GitHub Comments

29reactions
JohnGalt1717commented, Oct 26, 2018

So the reason we’re getting this is someone is trying to POST AND OPTIONS to /index.html not GET. Which causes this error message and causes a 500 error.

Of course of Azure/IIS sees too many errors in too short a time it tries and recycles the app. the problem is that it’s doing it over and over again which causes everything in that App Service Plan to crash. :<

How do we properly handle this without the site throwing a 500 error?

Note that this only happens in production, not development and as far as I can tell there is no way to handle this error with your own route. This is a major DOS attack vector in spa services that needs to be fixed ASAP.

20reactions
emilssonncommented, Mar 17, 2021

Another possible workaround is:

app.UseWhen(context => HttpMethods.IsGet(context.Request.Method), builder =>
{
    builder.UseSpa(spa =>
    {
    });
});

This will only run the SpaMiddleware for Get requests, letting all other request pass to the next middleware.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet build - get error "could not return the default page ' ...
InvalidOperationException : The SPA default page middleware could not return the default page '/index.html' because it was not found, and no ...
Read more >
The SPA default page middleware could not return ...
I got this error when I tried to run a released app Command used to publish dotnet publish --configuration Release Result: Hosting environment:...
Read more >
Error after publishing asp web api core with react app ...
System.InvalidOperationException : The SPA default page middleware could not return the default page '/index.html' because it was not found, and no other ...
Read more >
The SPA default page middleware could not return ...
When trying to debug app, getting error message in the browser: The SPA default page middleware could not return the default page '/index.html'....
Read more >
SPA middleware error - Ask us / Get help
InvalidOperationException : The SPA default page middleware could not return the default page '/index.html' because it was not found, and no ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found