8

I am developing three web applications that are part of a larger system. These are single page applications with an API, and as such I have wildcard route for non API actions that points to my main controller.

For two of these applications this works fine but for the third the redirect doesn't work and I just get a 404 returned when trying to access a front end route. The setup as far as I can tell is identical and I am completely stumped as to why it is not working.

I am using screenshots rather than code snippets so I can show the setup side by side (working on the left, not working on the right).

As you can see the key sections of code are identical in both applications and yet one works and one doesn't.

What have I missed? Where else should I look? And any guidance on how I can debug this would be greatly appreciated.

.csproj enter image description here

Startup.cs enter image description here

This is the key bit of code which as you can see is identical in both places:

app.UseMvc(routes =>
{
    routes.EnableDependencyInjection();
    routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
app.MapWhen(x => !x.Request.Path.Value.StartsWith("/api", StringComparison.OrdinalIgnoreCase), builder =>
{
    builder.UseMvc(routes =>
    {
        routes.MapRoute("spa-fallback", "{*url}", new { controller = "Home", action = "Index" });
    });
});

Program.cs enter image description here

Web.config enter image description here

4
  • I can suggest that you try to see the difference in code with a tool like WinMerge and maybe you find out something interesting Commented Aug 30, 2018 at 12:24
  • I've compared all these files with kdiff to no avail. Don't know if there is somwhere else I should be looking Commented Aug 30, 2018 at 12:25
  • Why the downvote whoever did that? How could I have asked this question better or added more information? Commented Aug 30, 2018 at 12:27
  • Are the projects the same project type and versions? Try comparing all the files in the project folders (including .sln and .csproj files etc.). It might be a version issue, some .properties file, manifest or similar. I assume, that you are running the projects the same way, on the same computer, and all in the same debug/release configuration? Commented Oct 23, 2018 at 14:19

1 Answer 1

1
app.UseMvc(routes =>
{
    routes.EnableDependencyInjection();
    routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
app.MapWhen(x => !x.Request.Path.Value.StartsWith("/api", 
StringComparison.OrdinalIgnoreCase), builder =>
{
    builder.UseMvc(routes =>
    {
        routes.MapRoute("spa-fallback", "{*url}", new { controller = "Home", action = 
"Index" });
    });
});

This has been solved. I looked at the code above which was routed with the home controller. This led me to look at the HomeController. The difference between the applications is that the one that is not working has a MVC Route attribute with an added "/" in the Home controller.

[Route("/")] // remove this line
public class HomeController : Controller
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.