Query without specifying columns returns wrong absolute url

George Tselios asked on March 17, 2020 23:13

Dear All,

In our current project (Kentico 12SP MVC), the development host name of our portal is dev.portal.com and the equivalent host name of the Kentico Admin Web Application is dev-cms.portal.com.

When we execute any type of query (DocumentQuery or MultiDocumentQuery) and we do not specify any column, then the absolute url of the resulting nodes is using the Kentico Admin's host name instead of the portals host name.

Here is an example of querying for an article node with id 45 and absolute url: http://dev.portal.com/en-us/my-article-page

 var query = DocumentHelper.GetDocuments()
    .Type("MyNameSpace.ArticlePage")
    .WithCoupledColumns()
    .Culture("en-US")
    .CombineWithDefaultCulture(false)
    .OnCurrentSite()
    .LatestVetextrsion()
    .WhereEquals("NodeID", 45)
    .TopN(1)
    .FirstOrDefault();

The above query will return a node whose absolute url will be http://dev-admin.portal.com/en-us/my-article-page which is wrong.

But the following query:

 var query = DocumentHelper.GetDocuments()
    .Type("MyNameSpace.ArticlePage")
    .Column("Title")
    .WithCoupledColumns()
    .Culture("en-US")
    .CombineWithDefaultCulture(false)
    .OnCurrentSite()
    .LatestVetextrsion()
    .WhereEquals("NodeID", 45)
    .TopN(1)
    .FirstOrDefault();

will return the same node but with the correct absolute url: http://dev.portal.com/en-us/my-article-page

In our queries we usually do not specify each and every column of the page we are querying for.

Please advise on how to resolve this issue.

Thanks in advance,
George

Correct Answer

Joseph Pickering answered on July 21, 2020 13:10

After getting in touch with Kentico support, I found out that you need these columns in order to produce the URL for a page.

.Columns("NodeAliasPath", "DocumentCulture", "DocumentNodeID")

1 votesVote for this answer Unmark Correct answer

Recent Answers


Peter Mogilnitski answered on March 18, 2020 01:59 (last edited on March 18, 2020 02:08)

First of all, it is a good performance practice (scroll down to tips) to add columns: Using Columns method you can restrict the amount of data loaded from the database and speed up the querying process. Secondly: You can always look what kind of SQL query was produced by your query builder:

DocumentHelper.GetDocuments()
    .Type("MyNameSpace.ArticlePage")
    .Columns("Title")
    .WithCoupledColumns()
    .Culture("en-US")
    .CombineWithDefaultCulture(false)
    .OnCurrentSite()
    .LatestVersion()
    .WhereEquals("NodeID", 45)
    .GetFullQueryText();

If you run these 2 queries in .SQL do you get different results?

P.S. Do DocumentHelper.GetDocuments("MyNameSpace.ArticlePage") instead DocumentHelper.GetDocuments() .Type("MyNameSpace.ArticlePage"). it should be a better performance.

P.P.S. I am thinking ... if you getting only title with coupled columns ... is it not enough to produce URL. You need the info from view_cms_tree_joined. Can share the code how your get the absolute URL?

0 votesVote for this answer Mark as a Correct answer

George Tselios answered on March 18, 2020 09:22

Dear Peter,

As I mentioned in my post, both SingleDocumentQuery and MultiDocumentQuery have the same behavior regarding the issue that I am talking about. The example of a MutliDocumentQuery was a random one.

We get the absolute url of the returned nodes by using the TreeNode.AbsoluteURL property.

Please note, the actual page (relative) url is the expected one but the domain of the absolute url is not correct.

Regards,
George

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on March 18, 2020 11:49

Hi George,

To me this looks like a very good question to Kentico support team. Have you tried to reach them at support@kentico.com as there might be a bug then?

0 votesVote for this answer Mark as a Correct answer

George Tselios answered on March 18, 2020 15:19

Dear Dimitry,

First of all thank you for your answer.

I used the Support form of devnet to forward the issue to support.

Regards,
George

0 votesVote for this answer Mark as a Correct answer

Joseph Pickering answered on June 11, 2020 12:27

@George Tselios Did you manage to resolve this? I'm currently having the same issue.

0 votesVote for this answer Mark as a Correct answer

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