C
C#2y ago
Up

ASP.NET MVC Legacy Route Hell

So I have a very old API that was originally written in MVC. this api manages projects where each project has an ID + user-friendly slug, and then has a bunch of files that each have file name + file ID. now I have an MVC route mapping that I will need to know how it resolves, so I can then extract those properties from the URL back to my own application.
1 Reply
Up
Up2y ago
routes.MapRoute<MavenApiController>(c => c.JarFile("", "", "", "", "", ""), constraints: apiConstraints, urls: new[]
{
"api/maven/{projectSlug}/{mavenArtifact}/{mavenVersion}/{projectFileNameArtifact}-{projectFileNameVersion}.jar",
"api/maven/{projectSlug}/{mavenArtifact}/{mavenVersion}/{projectFileNameArtifact}-{projectFileNameVersion}-{projectFileNameTag}.jar"
});
routes.MapRoute<MavenApiController>(c => c.JarFile("", "", "", "", "", ""), constraints: apiConstraints, urls: new[]
{
"api/maven/{projectSlug}/{mavenArtifact}/{mavenVersion}/{projectFileNameArtifact}-{projectFileNameVersion}.jar",
"api/maven/{projectSlug}/{mavenArtifact}/{mavenVersion}/{projectFileNameArtifact}-{projectFileNameVersion}-{projectFileNameTag}.jar"
});
so basically, for any given file name, how would I know 1. which of these 2 routes would be used (I am fine with simply sending a request to that URL and testing) and 2. how would I split the file name into the properties accordingly (so I can input them somewhere else)? for any given file I know the full file name, as well as the projectSlug part, and need to guess how the system split the filename