How can I find the route that matches a string url in ASP.NET MVC?
This is not for the purposes of debugging.
I am generating a link using Request.UrlReferrer
but we need to restrict this to specific controller actions in our application. Ideally we would so something like so:
@Url.PreviousUrl(
default: Url.Action("index", "home")
validRoutes: new[] {
new { controller = "list", "projects" }
new { controller = "tagged", "projects" },
new { controller = "details", "category" }
}
);
If the UrlReferrer
matches any of those routes then we will redirect to it, otherwise we will redirect to the default url specified.