The SPA default page middleware could not return the default page '/index.html' in production application
See original GitHub issueI 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:
- Created 5 years ago
- Reactions:36
- Comments:103 (14 by maintainers)
Top Related StackOverflow Question
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.
Another possible workaround is:
This will only run the SpaMiddleware for Get requests, letting all other request pass to the next middleware.