For a project I’ve to(unfortunately) match some exact url.
So I thought it will not be a problem, I can use the “MapRoute”, to match urls with the desired controller. But I can’t make it work.
I’ve to map this URL:
http://{Host}/opc/public-documents/index.html
to
Area: opc
Controller: Documents
Action: Index
Another example is to map
http://{Host}/opc/public-documents/{year}/index.html
to
Area: opc
Controller: Documents
Action:DisplayByYear
Year(Parameter): {year}
I tried this, whitout success, in my area(ocpAreaRegistration.cs):
context.MapRoute("DocumentsIndex", "opc/public-documents/index.html",
new {area="opc", controller = "Documents", action = "Index"});
context.MapRoute("DocumentsDisplayByYear", "opc/public-documents/{year}/index.html",
new {area="opc", controller = "Documents", action = "Action:DisplayByYear"});
But I got some 404 Errors 🙁 when I’m trying to access it. What am I doing wrong?
I’m not sure why you need to do this (I can only assume you’re coming from a legacy application), but this is working for me:
opcAreaRegistration.cs:
Controller:
Make sure you put those routes in the area routing file rather than global.asax and you should be good to go.