- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我需要读/写 ActiveDirectory 用户对象终端服务属性。我试过这个:
PrincipalContext context = new PrincipalContext(ContextType.Domain, "CA");
using (context)
{
UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "CA\\vlekovic");
if (user != null)
{
DirectoryEntry entry = (DirectoryEntry)user.GetUnderlyingObject();
entry.Properties["msTSProfilePath"].Value = "";
entry.Properties["msTSHomeDirectory"].Value = "";
entry.Properties["msTSHomeDrive"].Value = "";
entry.CommitChanges();
}
}
我试过这个:
PrincipalContext context = new PrincipalContext(ContextType.Domain, "CA");
using (context)
{
UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "CA\\vlekovic");
if (user != null)
{
DirectoryEntry entry = (DirectoryEntry)user.GetUnderlyingObject();
entry.InvokeSet("msTSProfilePath", "");
entry.InvokeSet("msTSHomeDirectory", "");
entry.InvokeSet("msTSHomeDrive", "");
entry.CommitChanges();
}
}
但没有任何作用。
我还尝试使用以下属性名称:
但运气不好。任何帮助将不胜感激!
谢谢,沃金
最佳答案
如果您使用的是 .NET 3.5 及更高版本并使用 System.DirectoryServices.AccountManagement
(S.DS.AM) 命名空间,则可以轻松扩展现有的 UserPrincipal
类以获得更高级的属性,如 Manager
等。
在这里阅读所有相关内容:
基本上,您只需定义一个基于 UserPrincipal
的派生类,然后定义您想要的其他属性:
[DirectoryRdnPrefix("CN")]
[DirectoryObjectClass("Person")]
public class UserPrincipalEx : UserPrincipal
{
// Implement the constructor using the base class constructor.
public UserPrincipalEx(PrincipalContext context) : base(context)
{ }
// Implement the constructor with initialization parameters.
public UserPrincipalEx(PrincipalContext context,
string samAccountName,
string password,
bool enabled) : base(context, samAccountName, password, enabled)
{}
// Create the "TermSrvProfilePath" property.
[DirectoryProperty("msTSProfilePath")]
public string TermSrvProfilePath
{
get
{
if (ExtensionGet("msTSProfilePath").Length != 1)
return string.Empty;
return (string)ExtensionGet("msTSProfilePath")[0];
}
set { ExtensionSet("msTSProfilePath", value); }
}
}
现在,您可以在代码中使用 UserPrincipalEx
的“扩展”版本:
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
{
// Search the directory for the new object.
UserPrincipalEx inetPerson = UserPrincipalEx.FindByIdentity(ctx, IdentityType.SamAccountName, "someuser");
// you can easily access the TermSrvProfilePath now
string path = inetPerson.TermSrvProfilePath;
}
同样,您也可以添加您要查找的其他属性。
关于c# - 如何使用 msTSProfilePath、msTSHomeDirectory 等扩展 C# DirectoryServices UserContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16967791/
我正在尝试将某种服务共享给嵌套在另一个组件中的组件,但出现未定义的错误。 'UserContext' is not defined no-undef 这是我的 App.js: import logo
我有一个模型 UserB2b扩展自 User .我已使用 server.authEnabled 启用授权在引导脚本中,以便所有请求都通过 auth 中间件。 问题:每当我的 UserB2b 中有一个非
我正在尝试创建一个可供 React 应用程序中的所有类组件访问的 UserContext。我收到以下错误。 ReferenceError: Cannot access 'UserContext' be
如何在 beforeEach() 函数中为 Jasmine 的 userContext 上的属性集提供类型? 我的代码: beforeEach(() => { this.injector =
我面临一个奇怪的问题,即在单击工具菜单下的扩展和更新时收到一条消息“值不能为空。参数名称为 userContext”。 请让我知道此问题的解决方法是什么。谢谢你。 最佳答案 我有完全相同的问题。我从开
我需要读/写 ActiveDirectory 用户对象终端服务属性。我试过这个: PrincipalContext context = new PrincipalContext(ContextType
我收到错误消息 'Value cannot be null. Parameter name: userContext' 在Visual Studio 2017中尝试单击通知或从tools文件夹中打开扩
我发现几乎每个类( Controller 、 View 、HTML 帮助程序、服务等)我都需要当前登录的用户数据。所以我考虑创建一个“环境上下文”而不是直接注入(inject) IUserServic
我是一名优秀的程序员,十分优秀!