I have basically an out-of-the box MVC 5.2 app, with attribute-based routes enabled (calling routes.MapMvcAttributeRoutes();
from the provided RouteConfig.Reg
The difference between errors you see is because when you try to access /hello.txt
IIS tries to reach the static resource file located on the server, on the other hand /hello404
is just an unknown route so 404 is thrown.
To ensure that I am right try to add slash at the end and access /hello.txt/
you should now get 404 error.
There are several ways to resolve this problem:
First you can try
but this option called RAMMFAR hurts the performance of web application. and has other consequences.
Second you can create rule for IIS URL REWRITE to always add trailing slash to each incoming URL's
Third go with Dots in URL causes 404 with ASP.NET mvc and IIS and
but you did not like this.
Fourth try to create custom http handler to add trailing slash to all requests like in this topic Add a trailing slash at the end of each url?
I would go with second option if you need this to work in many places in your application.
But I think the best one is third. Such url's with dots are not user friendly and are against SEO rules. You should avoid them in publicly available websites. So assuming you need this for only one controller and route this option is the fastest and cleanest one.