Hi,
I follow Johan Blog: http://world.episerver.com/Blogs/Johan-Bjornfot/Dates1/2012/11/Partial-Routing/, and I am able to make the outgoing route works, it shows correct value in the browser address, however, the incoming does not work as expected. After the partial return the object, it shows a 404 error, below is my code:
public class RoomPartialRoute : IPartialRouter<CommunityRoomPageData, RoomBase>
{
public const string RoomKey = "CurrentRoom";
private EPiServer.Community.Forum.Forum _currentForumValue;
#region Implementation of IPartialRouter<CommunityForumPageData,Room>
//The incoming request is something like
public object RoutePartial(CommunityRoomPageData content, SegmentContext segmentContext)
{
var namePart = segmentContext.GetNextValue(segmentContext.RemainingPath);
if (!String.IsNullOrEmpty(namePart.Next))
{
//var room = EntityUrlSegmentHandler.Instance.GetEntitiesByUrlSegment(CurrentForum, typeof(Room), namePart.Next) as RoomBase;
var room = ForumHandler.Instance.GetRoom(75);
if (room!= null)
{
segmentContext.SetCustomRouteData<RoomBase>(RoomKey, room);
}
return content;
}
return null;
}
public PartialRouteData GetPartialVirtualPath(RoomBase room, string language, RouteValueDictionary routeValues, RequestContext requestContext)
{
string roomUrlSegment;
EntityUrlSegmentHandler.Instance.GetUrlSegment(room, out roomUrlSegment);
return new PartialRouteData()
{
BasePathRoot = SiteSettingsHandler.Instance.SiteSettings.CommunityRoomPage,
PartialVirtualPath = String.Format("{0}/",roomUrlSegment)
};
}
public EPiServer.Community.Forum.Forum CurrentForum
{
get { return _currentForumValue ?? (_currentForumValue = ForumProvider.Instance.GetForumForCurrentSite()); }
}
#endregion
}
Can someone help me with this?
Before you call
return content;
you should update remainingpath (when you have "consumed" a segment) on the context like:
segmentContext.RemainingPath = namePart.Remaining;
otherwise the segment is not consumed and instead passed on to next segment. In default registered routes it would be the action segment. And if there is no action with that name a 404 is returned.
Hi,
We are trying to make the url of the forum move friendly, We can see that in the Relate 7 there is a built-in functionality for Blog, I wonder if we can create the same partial url for Forum and how can we do that.
Thank you very much n advance!