Translate a url to a route

Translate a url to a route

I feel like I'm re-inventing the wheel here, but I need to find a way of taking a URL from a catchall,and redirecting that to another route.

The reason for this is because I need to do some things like adding session cookies for certain urls, and then pass them on to their relevant action.

What's the best way of implementing this?

Thanks in advance for any help!

ASP.NET MVC ambiguous action methods


Using Inline C# inside Javascript File in MVC Framework

problems with ASP MVC + Html.DropDownList() using a ModelView Pattern

How do I access the ModelState from within my View (aspx page)?


Generic Model Representations In ASP.NET MVC
If I understand question.... Looking at your previous question (redirect-to-controller-but-with-a-different-master-using-a-catchall-wildcard) you want to take the wildcard from:.
routes.MapRoute(     "Partner",     "partners/{partner}/{*wildcard}",     new { controller = "Partners", action = "PartnerRedirect" } ); 
And in the Partners/PartnerRedirect action, send it to the right controller/action specified in the wildcard?. I have no idea the best way to do this, but looking at ways to unit test url routing brought up this: . I'm not sure if it is an exact fit (ie.

might not have to mock stuff), but it looks like all the data is returned from GetRouteData to pass to RedirectToAction method..


Oh, so you don't want a redirect? You want the URL to stay:. but serve up:. I don't have MVC at home, but couldn't you instead define your route differently?. Instead of:.
routes.MapRoute(     "Partner",     "partners/{partner}/{*wildcard}",     new { controller = "Partners", action = "PartnerRedirect" } ); 
routes.MapRoute(     "Partner",     "partners/{partner}/{controller}/{action}/{other stuff you need}",     new { /* whatever defaults you want */ } ); 
The action now has the partner variable to do whatever with, and you could add route constraints to partner so only valid ones match.. (I think) you could then use an action filter on your actions/controllers to do appropriate action based on the partner paramter (it should be in httpcontext of the filter, again I think!) so that you don't have to repeat code in every action if you want to do some basic checks/actions on partner.. Here is a decent write up on a lot of ways to skin that cat:.


No, it is effectively a redirect, but the redirect is not visible to the user (in much the same way as a Server.Transfer() is done in Web Forms.. The link you pointed at only uses one master page, whereas I have many master pages (close to 200).. I have thought of having separate route handlers for these partners, but the master page choice came into the equation.. I think I'm going to have to create a ViewExtension to overcome these problems....

94 out of 100 based on 64 user ratings 1114 reviews