Kentico 12 MVC console app

S T asked on February 23, 2024 12:32

I've built a small console application using docs from here: https://docs.kentico.com/k9/integrating-3rd-party-systems/using-the-kentico-api-externally. In the console app I just make a few manual pages using the Treenode.Insert() function. The app adds the pages to my local DB normally and even when I change the connection string to the DEV db it adds it there on the dev website, the problem is when I copy the published console app to the DEV server and run it, the tree node is NOT null but tree.SelectNodes().Count is 0. Even if I add .Path() or .OnSite() etc it cant find any nodes. Its weird because when I initialize the TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser) the authenticated user is the same public anonymous user as locally and if i change his firstname on dev I seem to get the right one so it points to the correct DB but cant find the tree. Any suggestions on what can be causing the issue ? Regards

Recent Answers


Brenden Kehren answered on February 23, 2024 15:16

The console app doesn't have the context of the site it's running in so you'd have to provide what site ID specifically you want to run it in.

What we do in these instances is create and run the console app locally, simply to test and provide a proof of concept. Then once we've determined it works, we convert it to a scheduled task and register the task with the CMS to run within the contenxt of the given site it was meant for.

1 votesVote for this answer Mark as a Correct answer

S T answered on February 26, 2024 10:09

Hi Brendan, I've looked into the DEV DB and the site ID is 1 but still when I hardcode it in the API I get the site but not the tree. SiteInfo siteInfo3 = SiteInfoProvider.GetSiteInfo(1); - get the site tree.SelectNodes().OnSite(1).FirstOrDefault() - null tree.SelectNodes().Path("/Home").OnSite(1).FirstOrDefault() - null Is there any other way except the scheduled task, it works locally but I would need it to run like an exe? Regards

0 votesVote for this answer Mark as a Correct answer

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