为什么我从LDAP属性中获取"System .__ ComObject"? [英] Why am I getting 'System.__ComObject' from my LDAP property?

查看:88
本文介绍了为什么我从LDAP属性中获取"System .__ ComObject"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将第一个承认这是刻板的和过去的编程.我以前从没看过广告,真的不了解它.我想那是我的下一个研究...

I'll be the first to admit that this is cut and past programming. I've never looked at AD before, and really don't understand it. I suppose that's my next study...

无论如何,这是一些测试代码,应该以任何可读的或滴答的形式显示到期日期,这无关紧要. (这是一个Web表单,正在开发Web服务器上运行.)

Anyways, This is some test code, which should display the expiry date -- either as something readable, or in ticks -- it doesn't matter. (It's a web form, which is running on the dev webserver.)

我得到的是:"System .__ ComObject"

What I get instead is: "System.__ComObject "

DirectorySearcher searcher = new DirectorySearcher();
searcher.Filter = String.Format( "(SAMAccountName={0})", "TestA33" );
searcher.PropertiesToLoad.Add( "cn" );

SearchResult result = searcher.FindOne();
DirectoryEntry uEntry = result.GetDirectoryEntry();

String expiry = uEntry.Properties["accountExpires"].Value.ToString(); 

Response.Write( expiry );

推荐答案

这是因为属性值是使用ADSI IADsLargeInteger COM接口表示的,并且需要转换为.NET日期. 尽管我还没有尝试过,但是这里有一个示例显示了如何: http://www. simple-talk.com/dotnet/.net-framework/building-active-directory-wrappers-in-.net/

It's because the property value is represented using the ADSI IADsLargeInteger COM interface and needs to be converted to a .NET date. Although I haven't tried it, there is a sample that shows how here: http://www.simple-talk.com/dotnet/.net-framework/building-active-directory-wrappers-in-.net/

这篇关于为什么我从LDAP属性中获取"System .__ ComObject"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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