Kentico UserInfoProvider not working as expected in a console app

前端 未结 3 1788
花落未央
花落未央 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: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();
          }
      }
      

提交回复
热议问题