Kentico UserInfoProvider在控制台应用程序中无法按预期工作 [英] Kentico UserInfoProvider not working as expected in a console app

查看:68
本文介绍了Kentico UserInfoProvider在控制台应用程序中无法按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码在Kentico网站上可以正常运行:

This code works fine within a Kentico website:

var users = UserInfoProvider.GetUsers();
for (int x = 0; x < users.Count(); x++
{
    UserInfo currentUser = users.ElementAt(x);
    currentUser.SetValue("AcceptsAlerts", equivalentSubscriber.Status != SubscriberStatus.Unsubscribed);
    UserInfoProvider.SetUserInfo(currentUser);
}

当我将代码移至控制台应用程序时,对UserInfoProvider的任何调用都会导致错误:找不到对象类型'cms.usersettings'"

When I move the code to a console app, any calls to UserInfoProvider result in the error: "Object type 'cms.usersettings' not found"

为了获得用户的初始呼叫,我可以在控制台应用程序中这样做:

For the initial call to get the users, I can do it like this in the console app:

DataSet usersds = new CMS.DataEngine.DataQuery("cms.user.selectall").Execute();

然后使用用户数据遍历数据集的Table1:

then loop through Table1 of the dataset using the user data:

UserInfo currentUser = new UserInfo(dtUsers.Rows[x]);

一切正常,并且可以正常工作,直到我将更新后的用户写回到数据库中为止.除了调用之外,我找不到其他写数据的方法:

All is fine and working, until I come to write the updated user back to the database. I cannot find another way of writing the data apart from calling:

UserInfoProvider.SetUserInfo(currentUser);

有人知道另一种保存用户数据的方法吗?或解决错误.该错误是运行时错误,据我所知,我已经引用了所有需要的内容.我正在编辑的字段是添加到cmsUser表的自定义字段.

Does anyone know another way to save the user data? or to resolve the error. The error is a runtime error and as far as I know, I have referenced everything I need to. The field I am editing is a custom field added to the cmsUser table.

使用语句获取信息:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using CMS;
using CMS.CustomTables;
using CMS.DataEngine;
using CMS.Membership;

推荐答案

从外部应用程序开始使用Kentico CMS API之前,请确保调用以下行:

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();

然后,您还可以使用UserInfoProvider.GetUsers()对象查询,而不是使用DataQuery.Execute().

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

这篇关于Kentico UserInfoProvider在控制台应用程序中无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆