Sometime API page aliases work incorrect

Ryan Nguyen asked on June 3, 2019 08:49

I writing a module, that editor can import/export aliases for their site.

Here is my steps:

  1. Read users content (page destination, page aliases)
  2. Create or update page aliases (docs: https://docs.kentico.com/api11/content-management/pages#Pages-Creatingapagealias)
  3. Clear system cache

I see the aliases from step 2 appear exactly in the CMS, but I got page not found when open aliases from browser, It does not redirect me to primary path. I tried new incognito browser and still 404.

I'm using k11, is there way to debug and fix this?

Recent Answers


David te Kloese answered on June 3, 2019 11:52

Hi,

Does adding the alias manually from the Administration work as you expect?

Do you also set the redirect behavior?

Or have you set the site wide setting:> "Use site settings (default) - with this option, the redirection behavior follows the Redirect page aliases to main URL setting specified for the website in Settings -> URLs and SEO."

Verify you use the correct culture for your alias in code... the .Culture("en-us") part for the document selection from the sample code.

1 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on June 3, 2019 12:05

In addition to David's answer, if you open your alias created via code in the Kentico admin interface and try to "re-save" it would it work?

If it is working then it means that you need to initialize some more properties of alias created in your code.

0 votesVote for this answer Mark as a Correct answer

Ryan Nguyen answered on June 3, 2019 12:15

Hi David te Kloese,

If I do this manually, it work fine, I also checked the option "Redirect page aliases to main URL" in "Settings -> URLs and SEO"

For the culture code,I'm using Culture() depend on users choice. (If they do not specific a culture, that mean they want to redirect all culture)

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on June 3, 2019 12:25 (last edited on June 3, 2019 12:25)

Since manually adding it does work you probably miss or wrongly set a property.

Easiest might be to just check the database what the difference between your code and manual insertion are:

sample

1 votesVote for this answer Mark as a Correct answer

Ryan Nguyen answered on June 3, 2019 17:41 (last edited on June 3, 2019 17:42)

I don't see any extraordinary record both CMS and database pls see my attachment.

Image Text

Image Text

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on June 4, 2019 10:12

Some of these do and some don't work?

If you tried what Dmitry said for a non-working:

if you open your alias created via code in the Kentico admin interface and try to "re-save" it would it work?

If it saves and then works it's either some cache or another settings or property is updated too.

0 votesVote for this answer Mark as a Correct answer

Ryan Nguyen answered on June 4, 2019 10:41

If I re-save in the CMS then it work. I tried to check properties, database but nothing difference between saving from CMS and my code. Also I already cleared system .

How to detect which property make them diff?

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on June 4, 2019 13:29

Could you share the exact code section you use to insert a new alias via code?

0 votesVote for this answer Mark as a Correct answer

Ryan Nguyen answered on June 5, 2019 02:41 (last edited on June 5, 2019 02:48)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.