LdapFilterEncode Method

Microsoft AntiXSS Library

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

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

Syntax

C#
public static string LdapFilterEncode(
	string input
)
Visual Basic
Public Shared Function LdapFilterEncode ( _
	input As String _
) As String
Visual C++
public:
static String^ LdapFilterEncode(
	String^ input
)

Parameters

input
Type: System..::..String
String to be encoded.

Return Value

Encoded string for use as a value in LDAP filter queries.

Remarks

This method encodes all but known safe characters defined in the safe list. RFC 4515 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. The following examples illustrate the use of the escaping mechanism.
Parens R Us (for all your parenthetical needs)Parens R Us \28for all your parenthetical needs\29
*\2A
C:\MyFileC:\5CMyFile
NULLNULLNULLEOT (binary)\00\00\00\04
LučićLu\C4\8Di\C4\87

See Also