문제

The SharePoint Code Analysis Framework rule SPC020220: Do not call 'HttpUtility.HtmlEncode' states that:

The assembly should not call HttpUtility.HtmlEncode(string) to encode strings [and that] SPHttpUtility.HtmlEncode [should be used] instead.

I don't understand the rationale. If I understand correctly, both methods perform the same thing. According to MSDN:

The HtmlEncode method replaces ampersand, double-quotation, single-quotation, less-than, and greater-than characters with the appropriate entity references.

So does HttpUtility.HtmlEncode(string).

  • Why preferring the first to the second?

  • What is a case where two methods will perform differently?

도움이 되었습니까?

해결책

The reason is explained in the link you had given.

"The .NET Framework HttpUtility encoding library does not encode all characters sufficiently. For example, SPHttpUtility in SharePoint encodes a single quotation mark as ' but .NET Framework HttpUtility does not encode the single quotation mark."

Apart from that, there isn't much preference i guess. The SPHttpUtility.HtmlEncode encodes few other characters that the HttpUtility does not encode.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top