November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hello,
You can register you're own route that includes you're own segment. Johan Björnfot has answered an forum post similar to this. Look here: http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=65422
Thank you Jonas,
In my case 2013.03/20/ is the part of the tree structure, it's not the parameter to load the pagedata. Also, is it possible apply the route to spectific pagetype?
Thank you very much!
An alternative could be to hook up to event ContentRoute.CreatedVirtualPath and modify the generated Url.
This would probably be a good approach if you have an easy recogizable pattern of the url you want to modify.
Note: If you use patch 2 to CMS7 then the event argument contains the RouteValues where you can find the ContentReference for the routed item.
Thank you very much Johan,
Could you please give us some more details about what to modify? A code example would be great!
Regards,
Hai
Is there anyway I can customize the {node} segment .i.e. I want to remove some part of the {node } segment, or override the {node} segment with something like {mynode}?
You could register your own route before the builtin ones. In your own route you could replace the segment handling {node} part with your own node implemetation. You could then e.g. create your own class that inherits EPiServer.Web.Routing.Segments.NodeSegment and have your logic there.
See the previous post pointed by Jonas to where you can find more info on how to do that.
If the approach Johan suggested doesn't work for you and you only want to customize the segment at creation time (i.e. not removing it) then I would suggest looking at the UrlSegment.CreatingUrlSegment event.
Thank you Johan and Ben!
I will give it a try and get back to you later.
Really appreciate yours help!
Regards,
Hai
Hi,
I have tried to write a custom {node} segment, basically copy the code of the NodeSegment and register it before the built-in segments as below:
routingParameters.SegmentMappings.Add("modnode", new CustomNodeSegment("modnode", UrlRewriteProvider.FriendlyUrlExtension, urlSegmentRouter, new LanguageSegmentMatcher(routingParameters.LanguageBranchRepository), routingParameters.ContentLoader, routingParameters.UpdateCurrentLanguage));
string name = "pages";
string str4 = "{modnode}/{partial}/{action}";
object obj3 = new
{
action = "index"
};
routes.MapContentRoute(name, str4, obj3);
base.RegisterRoutes(routes);
But it seems not run, the url still the same, one more question which method in NodeSegment should I override to put my own path? Maybe GetOutGoingurl?
To handle outgoing links you should override GetVirtualPathSegment. But since you are constructing your own urls you need to handle incoming routing as well so you need to override e.g. GetIncomingNode as well.
Thank you Johan,
I've created the custom segment as you suggested, however when we use it the startpage is move to the rootpage, we cannot view the startpage anymore, maybe I'm missing something :(.
Thank you very much!
It sounds like the "ordinary" route does not get a chance to handle the request.
You can think of all registered routes as "chained". That is only if one route does not handle a request the following routes in the chain will get a chance to handle the request.
So when implementing an own route it is important to not "capture" request that you do not handle since then follwing routes will not get a chance to route the request.
Thank you for the point Johan!
However I can still go to edit/admin mode as normal only view mode redirect me to the Root page. By the way, is there any chance for me to debug the custom segment? It seems that I cannot debug the file.
Thank you very much!
Hai
Yes you should be able to debug your segment. It should be no different to degug from other code (like controller, codebehind etc)
Thank you very much Johan,
I'm still not able to debug the segment. First I want to debug the current {node} segment implementation of EPiServer, I copied it from the Reflector, rename, overide the RegisterRoutes method. I delete all the rest rules, but it seems not work. Is there anyway which I can debug the original {node} segment?
Thank you very much!
Hai
Also, How can I create an instance of the {node} segment with its parameters:
routingParameters.SegmentMappings.Add(CustomRoutingConstants.CustomNodeKey, new CustomNodeSegment(CustomRoutingConstants.CustomNodeKey, UrlRewriteProvider.FriendlyUrlExtension, urlSegmentRouter, new LanguageSegmentMatcher(routingParameters.LanguageBranchRepository), routingParameters.ContentLoader, routingParameters.UpdateCurrentLanguage));
I used some parameter from the reflector, but I think it does not work, so some value was not added, this is how I did:
var routingParameters = new MapContentRouteParameters()
{
SegmentMappings = new Dictionary<string, ISegment>()
};
routingParameters.ServiceLocator = routingParameters.ServiceLocator ?? ServiceLocator.Current;
IRouteHandler routeHandler = routingParameters.RouteHandler;
if (routingParameters.ServiceLocator.AssignNullService<IRouteHandler>(ref routeHandler))
{
routingParameters.RouteHandler = routeHandler;
}
IUrlSegmentRouter urlSegmentRouter = routingParameters.UrlSegmentRouter;
if (routingParameters.ServiceLocator.AssignNullService<IUrlSegmentRouter>(ref urlSegmentRouter))
{
routingParameters.UrlSegmentRouter = urlSegmentRouter;
}
IRouteParser routeParser = routingParameters.RouteParser;
if (routingParameters.ServiceLocator.AssignNullService<IRouteParser>(ref routeParser))
{
routingParameters.RouteParser = routeParser;
}
ILanguageBranchRepository languageBranchRepository = routingParameters.LanguageBranchRepository;
if (
routingParameters.ServiceLocator.AssignNullService<ILanguageBranchRepository>(
ref languageBranchRepository))
{
routingParameters.LanguageBranchRepository = languageBranchRepository;
}
IViewRegistrator viewRegistrator = routingParameters.ViewRegistrator;
if (routingParameters.ServiceLocator.AssignNullService<IViewRegistrator>(ref viewRegistrator))
{
routingParameters.ViewRegistrator = viewRegistrator;
}
IContentLoader contentLoader = routingParameters.ContentLoader;
if (routingParameters.ServiceLocator.AssignNullService<IContentLoader>(ref contentLoader))
{
routingParameters.ContentLoader = contentLoader;
}
PartialRouteHandler partialRouteHandler = routingParameters.PartialRouteHandler;
if (routingParameters.ServiceLocator.AssignNullService<PartialRouteHandler>(ref partialRouteHandler))
{
routingParameters.PartialRouteHandler = partialRouteHandler;
}
TemplateResolver templateResolver = routingParameters.TemplateResolver;
if (routingParameters.ServiceLocator.AssignNullService<TemplateResolver>(ref templateResolver))
{
routingParameters.TemplateResolver = templateResolver;
}
IPermanentLinkMapper permanentLinkMapper = routingParameters.PermanentLinkMapper;
if (routingParameters.ServiceLocator.AssignNullService<IPermanentLinkMapper>(ref permanentLinkMapper))
{
routingParameters.PermanentLinkMapper = permanentLinkMapper;
}
IContentVersionRepository contentVersionRepository = routingParameters.ContentVersionRepository;
if (
routingParameters.ServiceLocator.AssignNullService<IContentVersionRepository>(
ref contentVersionRepository))
{
routingParameters.ContentVersionRepository = contentVersionRepository;
}
IUpdateCurrentLanguage updateCurrentLanguage = routingParameters.UpdateCurrentLanguage;
if (routingParameters.ServiceLocator.AssignNullService<IUpdateCurrentLanguage>(ref updateCurrentLanguage))
{
routingParameters.UpdateCurrentLanguage = updateCurrentLanguage;
}
You should not need to reflect out the CMS code. Look at the code example at
http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=65422
instead on how to register a route with a custom segment.
Hi,
We want to remove the {node} segment in the url so that the url will look shorter and easy to type :)
For example the current url is: www.mysite.com/article/2013.03/20/myarticle we want it to something like www.mysite.com/article/myarticle
any help will be greatly apreciated
Thanks,