Hi ,
We are using Episerver CMS 10 .
I have a news for which the URL is domain/nyheter/<newsname>
and we have implemented partial routing for that as below :
public object RoutePartial(ContainerBasePageType content, SegmentContext segmentContext) {
//Use helper method GetNextValue to get the next part from the URL
SegmentPair nextSegment = segmentContext.GetNextValue(segmentContext.RemainingPath);
NewsPageType newsContent = null;
// Find the global newspage that now has a url under local newscontainer.
if(!string.IsNullOrEmpty(nextSegment.Next)) {
string newsPageUrlSegment = nextSegment.Next.TrimEnd(new[] { '/' });
var companyPickerRef = ContentReference.StartPage;
var globalStartPage = this.contentLoader.GetChildren<MasterStartPageType>(companyPickerRef).FirstOrDefault();
if(globalStartPage != null) {
try {
newsContent = this.searchRepository.SearchForRoutedGlobalNews(newsPageUrlSegment, globalStartPage.ContentLink);
} catch(Exception ex) {
this.log.Error("Global news routing failed. Crash in Episerver Find routines" + ex);
}
}
if(newsContent != null) {
//Update RemainingPath so the part that we have handled is removed.
segmentContext.RemainingPath = nextSegment.Remaining;
segmentContext.RoutedContentLink = newsContent.ContentLink;
}
}
return newsContent;
}
//Makes every link of a newspagetype point to the local news page instead of global thing.
public PartialRouteData GetPartialVirtualPath(NewsPageType content, string language, RouteValueDictionary routeValues, RequestContext requestContext) {
var contentLink = requestContext.GetRouteValue("node", routeValues) as ContentReference;
if(!content.ContentLink.CompareToIgnoreWorkID(contentLink) || PageEditing.PageIsInEditMode || HttpContext.Current == null) {
return null;
}
ContentReference newsContainerRef = null;
PageData selectedCompanyStartPage = this.coreHelper.GetStartPageForRoutedContent();
if(selectedCompanyStartPage is LocalStartPageType) {
newsContainerRef = ((LocalStartPageType)selectedCompanyStartPage).NewsContainer;
}
return new PartialRouteData {
BasePathRoot = newsContainerRef,
PartialVirtualPath = content.urlsegment
};
}
}
}
but i want that it should follow hierachial structure for news
domain/nyheter/foldername/newsname so i have made changes in GetPartialVirtualPath as follows
var parentPage = contentLoader.Get<IContent>(content.ParentLink); //
PartialVirtualPath = String.Format("{0}/{1}/",
parentPage.Name,
HttpUtility.UrlPathEncode(content.Name))
but it is still giving 404 error
Thanks in advance !
Regards,
Titiksha Mahimker.