HttpUtility encode vs WebUtility encode

Hello guys, Today I have learned a difference between HttpUtility.HtmlEncode and WebUtility.HtmlEncode. If you use dot net version less than 4.7 then HttpUtility.HtmlEncode encodes the regional languages. If you want to only html tags need to encode th…


This content originally appeared on DEV Community and was authored by Santhosh N

Hello guys, Today I have learned a difference between HttpUtility.HtmlEncode and WebUtility.HtmlEncode. If you use dot net version less than 4.7 then HttpUtility.HtmlEncode encodes the regional languages. If you want to only html tags need to encode then use WebUtility.HtmlEncode.

var regionalText = "தமிழ்";
        var htmlText = "<script>alert('OK')";

        var httpUtilityRegionalText = HttpUtility.HtmlEncode(regionalText); //&#2980;&#2990;&#3007;&#2996;&#3021;
        var httpUtilityHtmlText = HttpUtility.HtmlEncode(htmlText); //&lt;script&gt;alert(&#39;OK&#39;)

        regionalText = "தமிழ்";
        htmlText = "<script>alert('OK')";

        var webUtilityRegionalText = WebUtility.HtmlEncode(regionalText); //தமிழ்
        var webUtilityHtmlText = WebUtility.HtmlEncode(htmlText); //&lt;script&gt;alert(&#39;OK&#39;)


This content originally appeared on DEV Community and was authored by Santhosh N


Print Share Comment Cite Upload Translate Updates
APA

Santhosh N | Sciencx (2021-06-14T11:23:48+00:00) HttpUtility encode vs WebUtility encode. Retrieved from https://www.scien.cx/2021/06/14/httputility-encode-vs-webutility-encode/

MLA
" » HttpUtility encode vs WebUtility encode." Santhosh N | Sciencx - Monday June 14, 2021, https://www.scien.cx/2021/06/14/httputility-encode-vs-webutility-encode/
HARVARD
Santhosh N | Sciencx Monday June 14, 2021 » HttpUtility encode vs WebUtility encode., viewed ,<https://www.scien.cx/2021/06/14/httputility-encode-vs-webutility-encode/>
VANCOUVER
Santhosh N | Sciencx - » HttpUtility encode vs WebUtility encode. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/14/httputility-encode-vs-webutility-encode/
CHICAGO
" » HttpUtility encode vs WebUtility encode." Santhosh N | Sciencx - Accessed . https://www.scien.cx/2021/06/14/httputility-encode-vs-webutility-encode/
IEEE
" » HttpUtility encode vs WebUtility encode." Santhosh N | Sciencx [Online]. Available: https://www.scien.cx/2021/06/14/httputility-encode-vs-webutility-encode/. [Accessed: ]
rf:citation
» HttpUtility encode vs WebUtility encode | Santhosh N | Sciencx | https://www.scien.cx/2021/06/14/httputility-encode-vs-webutility-encode/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.