I'm using .NET MVC 2 If an incoming request contains the URL:
http://something.com/1234
where 1234 is an {id} parameter. I want to be able to use the id to get some data from a database and then change the URL so that it goes to a valid controller and action.
The new URL should look something like:
http://something.com/area/username/controller/action/id
where the original id (1234) is looked up in the database and the data would translate to a specific {username}/{controller}/{action}/{id}.
I have the following routes set up in an AreaRegistration class:
context.MapRoute(
"route1",
"area/{controller}/{action}/{id}",
new { action = "Index", controller = "Home" },
new string[] { "MyApp.Areas.Controllers" }
);
context.MapRoute(
"route2",
"area/{controller}/{id}",
new { action = "Index", controller = "Home" },
new string[] { "MyApp.Areas.Controllers" }
);
What I can't seem to figure out is how/where to lookup the database data and change/rewrite the URL. I have tried implementing a custom RouteHandler and RouteBase but neither seem to do what I need.
This is my first SO post so forgive me if my question isn't clear. Any suggestions are appreciated.