C
C#2y ago
palapapa

✅ Why is the trailing dot of a route template optional?

Here https://learn.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-7.0#route-templates it mentions that "If only a value for filename exists in the URL, the route matches because the trailing . is optional." But just before that it says "Literal text other than route parameters (for example, {id}) and the path separator / must match the text in the URL. "
Routing in ASP.NET Core
Discover how ASP.NET Core routing is responsible for matching HTTP requests and dispatching to executable endpoints.
4 Replies
JakenVeina
JakenVeina2y ago
because that's the general practice when serving up literal files traditional HTTP file servers will auto-fill the file extension, when not given, depending on config the article is pointing out that if you're not careful and mix file serving routes together with data serving routes, you may run into ambiguities generally, you are not going to be using route templates together with file serving not unless you're building something like a CDN
palapapa
palapapaOP2y ago
Does this mean that asp.net do this not because of the server it's installed on does this, but because this is what most of the time happens so it just uses this behavior? I thought so because the purpose of asp.net is basically to run a program whenever a request comes in, so it seems strange that the config of the server can affect how route templates function in a C# program, so it must be asp.net itself that do this right?
JakenVeina
JakenVeina2y ago
....yes it is a behavior of ASP.NET Core itself the routing system because the designers made it that way
palapapa
palapapaOP2y ago
It's weird that this isn't documented. At least I didn't find it

Did you find this page helpful?