转义非特殊字符字符串LDAP查询

编程入门 行业动态 更新时间:2024-10-26 12:34:15
本文介绍了转义非特殊字符字符串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查询

本文发布于:2023-10-13 17:13:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1488590.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   特殊字符   LDAP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!