November Happy Hour will be moved to Thursday December 5th.

Different url based on page type

Vote:
 

Hello everyone i need to change the url based on he page type and i haven;t found a good way to do this. 

i have found this post

http://joelabrahamsson.com/custom-routing-for-episerver-content/

https://tedgustaf.com/blog/2008/create-a-custom-url-rewrite-provider-for-episerver/

and this one but they don't seem to work in 9 ?

Any help would be appreciated.

Thanks

PK

#172473
Dec 05, 2016 5:04
Vote:
 

Hi Paul! Can you provide a little bit more information on what you are trying to accomplish? Maybe provide some sample URLs that are hoping to acheive...

#172753
Dec 10, 2016 6:41
Vote:
 

Chris

Thanks for replying.  Sorry it took me so long to respond.  i was gathering the resources for this post and there are a bunch of them:) Watch out!

Currently we installed this blog template on episerver 9 

http://world.episerver.com/blogs/Jacob-Khan/Dates/2014/9/Blog-Template-for-EPiServer-CMS-75/

it wrks just fine. The urls out of the box are 

domain/startpage/year/month/blogtitle

They want domain/startpage/blogtitle

I found this 

http://joelabrahamsson.com/custom-routing-for-episerver-content/

and parts of it works and other parts do not work for me

I am able to modify the simple address according to the url name and buld the url the way i want and set the external url the way they want.  unfortunatly the uls do not go anywhere.  the only url that works is the 

domain/startpage/year/month/blogtitle

one.  i tried to add a new route 

 protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
}

 protected new void RegisterRoutes(RouteCollection routes)
        {
            routes.MapRoute(
               "BlogItem", // Route name
               "{action}/{id}", // URL with parameters
               new { controller = "BlogItemController", action = "blog" } // Parameter defaults
           );
            routes.MapRoute(
              "BlogItem", // Route name
              "blog/{id}", // URL with parameters
              new { controller = "BlogItemController", action = "blog" } // Parameter defaults
          );
        }



but after seeting the url manually and saving the externalurl the routs are not being hit for some reason.

I looked into how the blog item is rendered and it is a partial.  

Here is the part that i have working 

 public class BlogPartialRouterBlogItems : IPartialRouter<BlogStartPage, BlogItemPage>
    {
        public static PageData CurrentPage
        {
            get
            {
                if (HttpContext.Current == null)
                    return null; //throw new NotSupportedException("Cannot get current page without HttpContext");

                var pageBase = HttpContext.Current.Handler as PageBase;
                if (pageBase == null)
                    return null; //throw new NotSupportedException("Cannot get current PageBase object");

                var currentPage = pageBase.CurrentPage;
                if (currentPage == null)
                    return null; //throw new NotSupportedException("Current page is not set.");

                return currentPage;
            }
        }

        public PartialRouteData GetPartialVirtualPath(BlogItemPage BlogPage, string language, RouteValueDictionary routeValues, RequestContext requestContext)
        {
            var contentLink = ContentRoute.GetValue("node", requestContext, routeValues) as ContentReference;
         
            if (PageEditing.PageIsInEditMode)
            {
                return null;
            }

            string UrlToBeDisplayed = GetBlogPrefix(BlogPage.URLSegment);
            PageData currentPage = CurrentPage;
            //if (currentPage != null && !String.IsNullOrEmpty(currentPage.ExternalURL))
            //    UrlToBeDisplayed = currentPage.ExternalURL;


            var routData = new PartialRouteData
            {

                BasePathRoot = ContentReference.StartPage,
                PartialVirtualPath = UrlToBeDisplayed
                 //BasePathRoot = _blogStart,
                 //PartialVirtualPath = String.Format("{0}/{1}/", BlogPage.Name, BlogPage.Name)
             };
           
            return routData;
        }

/* more code down here that is not relevant */
}

Also we talked to one of the episerver reps and he sent these links but most of them are out dated ( mostly for epi 7 ) and some of the major parts are not compatable.  at least i haven't found a way to get them to work.

Any sugestions would be greatly appreciated!

Thank you!

#173069
Dec 13, 2016 18:40
* 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.