转义非特殊字符字符串LDAP查询 [英] Escaping non special characters in string for LDAP query

查看:1536
本文介绍了转义非特殊字符字符串LDAP查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我合适的名称,这个问题。这里的混合学科的位。

I hope that I have titled this question appropriately. Bit of a mixed subject here.

我已经创建了 C#函数创建一个Active Directory用户。使用需要像这样的LDAP字符串:

I have created a function in C# that creates an Active Directory User. Using an LDAP string that needs to look like this:

userinfo.displayName = "Surname, Firstname"

CN=" + userinfo.displayName, "user"

以下异常信息被传递回,因为逗号的字符串是的。

The following exception message is passed back, because of the comma being in the string.

这是无效的dn语法已指定。

An invalid dn syntax has been specified.

字符串已经被应用后,完整DN是如下

The full dn after the string has been applied is as following

"CN=Surname**,** Lastname,OU=Users,DC="Foo",DC="net"

中的公用名CN逗号=是问题...

The comma in the common name CN= is the problem...

有没有一种方式,C#可以忽略逗号出字符串的?有效地逃避它。

Is there a way that C# can ignore the comma out of the string? Effectively escaping it.

推荐答案

在一个专有名称转义无效字符是用斜线完成('\')。例如,上面的专有名称应该是:

Escape invalid characters in a distinguished name is done with a leading slash ('\'). For example, the distinguished name above should be:

"CN=Surname\, Lastname,OU=Users,DC=Foo,DC=net"

照见的 RFC 4514:轻型目录访问协议(LDAP):专用名称的字符串表示,字符 + ; < = > \ 可通过领先的斜杠进行转义。其他非字母数字字符应的形式显示 \XX 其中XX是UTF8字符编码的十六进制数字。示例请参见第4节。

According to section 2.4 of See RFC 4514: Lightweight Directory Access Protocol (LDAP): String Representation of Distinguished Names, the characters , ", #, +, ,, ;, <, =, >, and \ can be escaped by a leading slash. Other non-alphanumeric characters should be shown in the form of \XX where XX are the hex digits of the UTF8 character encoding. See section 4 for examples.

注意 X500DistinguishedName 类(在System.Security密码)没有出现有分析或逃生方法,在这种情况下提供帮助。

Note that the X500DistinguishedName class (in System.Security Cryptography) does not appear to have a Parse or Escape method to help in this situation.

这篇关于转义非特殊字符字符串LDAP查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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