views:

43

answers:

1

I have created the following RedirectToRouteResult:

new RedirectToRouteResult(new RouteValueDictionary{
                    { "controller", "Login" },
                    { "action", "Failed" },
                    { "ReturnUrl", filterContext.HttpContext.Request.Url.PathAndQuery }
                });

This fails to find the specified route (which I know works if typed in browser by hand). However if I add in the name of the route like below it works fine, but I don't get why.

new RedirectToRouteResult("Login_failed",
                new RouteValueDictionary{
                    { "controller", "Login" },
                    { "action", "Failed" },
                    { "ReturnUrl", filterContext.HttpContext.Request.Url.PathAndQuery }
                });

I didn't think I would have to specify the name if all the correct values were there?

A: 

Routing will return the first matching route and it's quite possible to have several routes that would match given RouteValues, make sure you have the most specific routes come first, falling back to the general routes at the end.

This would be easier if you could post the routes you have defined.

Chao