Sneaky Catch-All

July 12, 2020
dev asp.net-core

Didn't know that you had a catch-all, did you? How long did it take you to find this insidious little error? 3 days for me. The second time I was looking for it.

Sometimes we want a catch-all. We don't desire a 404, or even if we do, we rather show the user something more custom. This is typical with SPA projects inside of an ASP.NET project since we want the server to load up a default page when nothing matches since the server may not be aware of all the html, templates, etc.

That's nice.

But when that's not the case, but your home page comes up no matter what...why? You go through your startup, 100 times. You look at the output. You just can't figure out, no matter what, why is your home page always showing up. .com/hghghghg - yes, we can match that.

This is the second time, my cleverness and "what someone would see" bit in the booty.

The home page as a summary of widgets. I see mine. But, as a Powerful Admin User, I would like to see what Bob sees. So, I add a nice little route in the page "{id?}" add it to the model and puuuurfect. When I want to see Bob's view, I add /566566 and voila - just like that.

But, in my cleverness, asp.net says, "Yes, Sir! I will do as you say!"

So when you type in /manifest.json (which I don't have) - yes, here's that home page.

Adding that to the home pages route basically creates a catch-all. Isn't that nice.

Drop the route, add it as a querystring and things are better.

If you want to keep the route, you can add a constraint. Perhaps an int or Guid. Alternatively, be more specific, maybe /other_person/{id}.

That's that.