LdapDistinguishedNameEncode Method (String, Boolean, Boolean)

Microsoft AntiXSS Library

Collapse imageExpand ImageCopy imageCopyHover image
Encodes input strings for use as a value in Lightweight Directory Access Protocol (LDAP) DNs.

Namespace: Microsoft.Security.Application
Assembly: AntiXssLibrary40 (in AntiXssLibrary40.dll) Version: 4.2.0.0

Syntax

C#
public static string LdapDistinguishedNameEncode(
	string input,
	bool useInitialCharacterRules,
	bool useFinalCharacterRule
)
Visual Basic
Public Shared Function LdapDistinguishedNameEncode ( _
	input As String, _
	useInitialCharacterRules As Boolean, _
	useFinalCharacterRule As Boolean _
) As String
Visual C++
public:
static String^ LdapDistinguishedNameEncode(
	String^ input, 
	bool useInitialCharacterRules, 
	bool useFinalCharacterRule
)

Parameters

input
Type: System..::..String
String to be encoded.
useInitialCharacterRules
Type: System..::..Boolean
Value indicating whether the special case rules for encoding of spaces and octothorpes at the start of a string are used.
useFinalCharacterRule
Type: System..::..Boolean
Value indicating whether the special case for encoding of final character spaces is used.

Return Value

Encoded string for use as a value in LDAP DNs.

Remarks

This method encodes all but known safe characters defined in the safe list. RFC 2253 defines the format in which special characters need to be escaped to be used inside a search filter. Special characters need to be encoded in #XX format where XX is the hex representation of the character or a specific \ escape format. The following examples illustrate the use of the escaping mechanism.
, + \ " \ < >\, \+ \" \\ \< \>
hello\ hello
hello hello\
#hello\#hello
LučićLu#C4#8Di#C4#87
If useInitialCharacterRules is set to false then escaping of the initial space or octothorpe characters is not performed;
, + \ " \ < >\, \+ \" \\ \< \>
hello hello
hello hello\
#hello#hello
LučićLu#C4#8Di#C4#87
If useFinalCharacterRule is set to false then escaping of a space at the end of a string is not performed;
, + \ " \ < >\, \+ \" \\ \< \>
hello hello
hello hello
#hello#hello
LučićLu#C4#8Di#C4#87

See Also