Try our conversational search powered by Generative AI!

How to add category in page url?

Vote:
 

I have a child page under start page as shown below. How to access child page with url "startpage/category/childpage." Normally we get url as "startpage/childpage" where category is property of PageData.

#204281
May 24, 2019 8:40
Vote:
 

You can define a InitializableModule, inherit it from IInitializableHttpModule.

Then bind you event like:

public void InitializeHttpEvents(HttpApplication application)
{
       application.PreRequestHandlerExecute += this.ApplicationOnBeginRequest;
}

Now, inside your ApplicationOnBeginRequest method

private void ApplicationOnBeginRequest(object sender, EventArgs eventArgs)
{
     var contentRouteHelper = ServiceLocator.Current.GetInstance<IContentRouteHelper>();
     if (contentRouteHelper?.Content is PageData myPage)
     {
          var cat = myPage.Category.First();
          var redirect = contentRouteHelper.Content.ParentLink + cat.ToString() + contentRouteHelper.ContentLink;
          HttpContext.Current.Response.Redirect(redirectUrl);
     }
     
}
  1. Check if the request is for PageData type (as in above example)
  2. Get your category (I tried only first category).
  3. Format your url then redirect to it.

Note: This is high level idea only. Put proper null checks and exception handling.

Thanks & Regards

Praful Jangid

#204296
May 24, 2019 13:17
* 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.