If your route is not for content (that is it is a "standard" ASP.NET route) then you could consider using MapRoute extension method from System.Web.Mvc instead for MapContentRoute.
No it is for content. My LoginPage is a contentpage, I just want that /welcome/{id} also reaches my LoginPage.
Somehow none of the content routes are working. I created a page named WelcomePage so the default route i defined should kick in:
routes.MapContentRoute(
"default_node",
"{node}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
/Welcome is working, /Welcome/Index is working /Welcome/Index/1 is not working. /Welcome/Index?id=1 is working. It turns out that my url is being resolved by the default MVC route:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
When I remove this route i still got an error, only a different one. It really looks like somehow this route defnition is not matched. None of the MapContentRoute definitions are working.
I tried creating a custom Segment but my RouteDataMatch and GetVirtualPathSegment are not being hit.
I have not tried any of suggestions below but theoretically I think both should be possible..
If you go for the "default" MVC route you should probably register it after the CMS routes, you could aciehve this by doing registration in an event handler to EPiServer.Global.RoutesRegistered
If you go for a CMS route you will need to set the route to start route at the contentreference for your login page. Something like:
var segmentRouter = ServiceLocator.Current.GetInstance<IUrlSegmentRouter>();
segmentRouter.RootResolver = (sd) => referenceToYourLoginPage;
MapContentRouteParameters parameters = new MapContentRouteParameters()
{
UrlSegmentRouter = segmentRouter,
Direction = SupportedDirection.Incoming
};
routes.MapContentRoute(
"loginroute",
"welcome/{node}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
routes.MapContentRoute(name, url, defaults, parameters);
Then the routing will start at your login page, {node} segment will not consume any segment from url but it is required since it will set the routed content to login page.
Hi,
I want to add a route to my RouteConfig which 'redirects' a user from one page to another.
I have "Login" page with a LoginPageController and a Index action. My default route is wokring fine:
Now I want to create a new route which handles alle requests going to "/welcome/{id}" to this login page.
When I do this, I get the following error: "The provided content link does not have a value". This error is thrown by the Get<T> method in EPiServer.DataFactory.
This is my route configuration:
How can I fix this? Is this possible? Maybe I should use MapContentRouteParameters?
Hope somebody can help