profile
viewpoint

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

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?

aspnet/AspNetCore

Answer questions naveedahmed1

Any update on this? None of the above mentioned solutions fix the problem:

spa.Options.SourcePath

Since spa.Options.SourcePath is used in Development, as per my understanding its completely ignored in Production.

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.

I can confirm that its not any bot or someone sending requests to Index.html. I have CloudFlare on my website, I setup a Page Rule to redirect all requests to Index.html to https://www.mywebsite.com/. But still seeing the 404 errors for Index.html in my log.

Would be nice if an error wasn't the default behavior. I was able to prevent the exceptions using a rewrite rule in my web.config.

<rewrite>
  <rules>
    <rule name="Prevent requests to index">
      <match url="^index\.html$" />
      <action type="Redirect" url="/" redirectType="Permanent" appendQueryString="true" />
    </rule>
  </rules>
</rewrite>

Even setting Redirect Rule in web.config doesn't work.

Solution was to call UseMvc and UseSpa (inside Configure method) in correct order.

Using wrong order can produce similar error but the issue discussed here is different, and it occurs even with correct order. In case of wrong order,it will always return Index.html. But the issue being discussed here is about the random 404 errors for index.html in log, despite the website seems to be working fine.

useful!
source:https://uonfu.com/
answerer
Naveed Ahmed naveedahmed1 TechnoBird Islamabad, Pakistan https://www.mustakbil.com/ Founder & CEO Mustakbil.com
Github User Rank List