I have setup a routing table in the global.asax file for images that have been moved to the database. When I use the url such that EmpImages/[numeric id] as a basic format, it works fine if I use the url that does that same ~/EmpImages/42, but we have hundreds of hardcoded links that are ~/EmpImages/42.png. When I try to use the EmpImages/[numeric id].png, the handler is never called.
I have looked at several samples that show the .ext, but they are using page routes instead of handlers. With the code below, can you tell me what I’m missing?
This part works:
RouteTable.Routes.Add(new Route("EmpImages/{id}/{size}", new EmployeeImageRouteHandler()));
RouteTable.Routes.Add(new Route("EmpImages/{id}", new EmployeeImageRouteHandler()));
When using the URL:
~/EmpImages/42
~/EmpImages/42/256
But when I try:
RouteTable.Routes.Add(new Route("EmpImages/{id}/{size}.png", new EmployeeImageRouteHandler()));
RouteTable.Routes.Add(new Route("EmpImages/{id}.png", new EmployeeImageRouteHandler()));
When using the URL:
~/EmpImages/42.png
~/EmpImages/42/256.png
It fails. The handler is never called.
What simple thing am I missing?
According to the documentation for Route, it seems that the way you are specifying the route is unsupported.
Quoting the docs:
Apparently, it does not support segments with mixed URL parameters and literals.
You need to have your EmployeeImageRouteHandler internally deal with the “.png” extension of the size parameter with string processing.
EDIT: In addition to this point, it seems that there is a known problem in handling URLs with dots see this StackOverflow question . The solution proposed there is to include
in your web.config, but this works only for ASP 4.0 and IIS 7.0 and above. The details of this problem, as mentioned in the indicated question, are discussed on Haacked.