The problem with setting up IIS UrlRewrite rules for ASP.NET Core 3.1 after migration

I am trying to do a migration for the ASP.NET Core Web Application from 2.2 to 3.1. The frontend app for the application is Angular. This is the working asp.net core 2.2 piece of code from Startup.cs:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    //...

    app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
    
    app.UseAuthentication();
    ConfigureUrlRewriting(app, env);
    ConfigureRouting(app);
}

private static void ConfigureUrlRewriting(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment() && File.Exists("IISUrlRewrite.xml"))
    {
        using (var reader = File.OpenText("IISUrlRewrite.xml"))
        {
            var options = new RewriteOptions().AddIISUrlRewrite(reader);
            app.UseRewriter(options);
        }
    }
}

private static void ConfigureRouting(IApplicationBuilder app)
{
    app.UseDefaultFiles(new DefaultFilesOptions
    {
        DefaultFileNames = new List<string> { "index.html" }
    });
    app.UseStaticFiles();
    app.UseMvc(routes =>
    {
        routes.MapRoute(name: "default", template: "api/{controller}/{id}");
    });
}

After migration to asp.net core 3.1 following the guide from Microsoft docs the code changed like:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    //...

    app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
    
    app.UseAuthentication();
    ConfigureUrlRewriting(app, env);
    ConfigureRouting(app);
}


private static void ConfigureUrlRewriting(IApplicationBuilder app, IHostEnvironment env)
{
    if (env.IsDevelopment() && File.Exists("IISUrlRewrite.xml"))
    {
        using (var reader = File.OpenText("IISUrlRewrite.xml"))
        {
            var options = new RewriteOptions().AddIISUrlRewrite(reader);
            app.UseRewriter(options);
        }
    }
}

private static void ConfigureRouting(IApplicationBuilder app)
{
    app.UseDefaultFiles(new DefaultFilesOptions
    {
        DefaultFileNames = new List<string> { "index.html" }
    });
    app.UseStaticFiles();

    // Changed only the lines below
    app.UseRouting();
    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllerRoute(name: "default", pattern: "api/{controller}/{id}");
    });
}

After deploying on IIS local server there is the problem that all requests for static files returns index.html Here's the proof:

pic1

Here's the content of IISUrlRewrite.xml:

<rewrite>
  <rules>
    <rule name="AngularJS Routes" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/(api)/" negate="true" />
      </conditions>
      <action type="Rewrite" url="/" />
    </rule>
  </rules>
</rewrite>

Seems like the condition <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> is not matched for the static files. But the condition is mathed when the app is asp.net core 2.2

Can someone explain please this behaviour after migration? Is it the problem of .net core code or IIS-side problems?