Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Partial Routing for Community Forum in MVC

Vote:
 

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!

 

#69652
Apr 02, 2013 9:40
Vote:
 

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?

#69693
Edited, Apr 03, 2013 6:33
Vote:
 

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.

#69694
Apr 03, 2013 8:12
Vote:
 

Thank you very much Johan, it did the trick! 

Everything works just fine now.

Regards,

Hai

#69833
Apr 08, 2013 9:48
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.