Kentico UserInfoProvider not working as expected in a console app

前端 未结 3 1738
花落未央
花落未央 2021-01-28 09:24

This code works fine within a Kentico website:

var users = UserInfoProvider.GetUsers();
for (int x = 0; x < users.Count(); x++
{
    UserInfo currentUser = us         


        
相关标签:
3条回答
  • 2021-01-28 10:01

    Before you start working with Kentico CMS API from an external application make sure you call the following lines:

    CMS.DataEngine.ConnectionHelper.ConnectionString = "your connection string";
    CMS.Base.SystemContext.WebApplicationPhysicalPath = Application.StartupPath;
    CMS.DataEngine.CMSApplication.Init();
    

    Then, you'll be also able to use UserInfoProvider.GetUsers() object query instead of using DataQuery.Execute().

    0 讨论(0)
  • 2021-01-28 10:07

    For anyone looking to get a SiteID to use in API calls from an external app such as getting an email template, this might help you. In Kentico 8.1 you can go to Sites > General and get the code name for your site. Then you can do this:

    int siteID = CMS.SiteProvider.SiteInfoProvider.GetSiteID("<your site code name>");
    

    Hope it helps!

    0 讨论(0)
  • 2021-01-28 10:12

    Are you sure you are referencing all necessary assemblies?

    Following scenario works on my machine with configuration: Kentico 8.x, Web Application project

    1. Reference in your Console application these assemblies from lib folder

      • CMS.Base
      • CMS.DataEngine
      • CMS.DataProviderSQL
      • CMS.Membership
    2. Then copy your Connection String from Web Application's web.config to Console Application's App.config.

    3. After that you can use this code to set custom user properties

      static void Main(string[] args)
      {
          var users = UserInfoProvider.GetUsers();
      
          foreach (var user in users)
          {
              user.SetValue("myTestString", "test");
              user.Generalized.SetObject();
          }
      }
      
    0 讨论(0)
提交回复
热议问题