Skip to content

MapFallbackToFile is returning 404 #49738

@HarelM

Description

@HarelM

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

MapFallbackToFile doesn't return the required file

Expected Behavior

The required file should be returned when no middleware is hit.

Steps To Reproduce

The following is the project program file:

app.UseResponseCompression();
    app.UseCors(b => b.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
    app.MapControllers();
    app.MapHealthChecks("/api/health");
    // wwwroot
    app.UseDefaultFiles();
    app.UseStaticFiles(new StaticFileOptions
    {
        ContentTypeProvider = new FileExtensionContentTypeProvider
        {
            Mappings = { {".pbf", "application/x-protobuf"} } // for the fonts files
        }
    });
    app.UseSwagger();
    app.UseSwaggerUI(c =>
    {
        c.SwaggerEndpoint("/swagger/v1/swagger.json", "Israel Hiking Map API V1");
    });
    // This should be the last middleware
    app.UseMiddleware<CrawlersMiddleware>();
    app.MapFallbackToFile("/index.html");

It can be found here:
https://github.com/IsraelHikingMap/Site/blob/58dbe698bff288d9d24466ffa5a604535b2a2f93/IsraelHiking.Web/Program.cs#L41

Exceptions (if any)

No exception, just 404 when surfing to unknown route such as:
localhost:5000/map/1/2/3

.NET Version

7.0.202

Anything else?

This is not the first issue I'm having with trying to properly define the middlewares for my SPA project.
See the following issue: #45903
The fact that I'm getting it wrong so easily means that the code here is now well documented and doesn't do what is expected of it, especially in this case the MapFallbackToFile.

Every time I try to change this initialization code something else breaks, and my project is not that complicated, honestly.
The documentation is writing about the parameters instead of giving good examples of how one should be using the calls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions