How to convert string to HTML safe string

TruthOf42

I am creating a some dynamically generated HTML

bldr.AppendLine("<a>");
string userText = user.Company;
bldr.AppendLine(userText);
bldr.AppendLine("</a>");

How can I ensure that whatever the company's name is, will appear as it should, but also if they try to inject any HTML in thier name it will simply appear in plain text.

For instance if they tried to use the name "<script>alert("Do Bad!")</script>" that's exactly what will appear on the page, in plain text.

But I also want to avoid "A & C" translating to "A \u0026 C", which is what happens when I use

HttpUtility.JavaScriptStringEncode(user.Company);
Felipe Oriani

You can use the same class HttpUtility you have use to javascript, but, for html, for sample:

bldr.AppendFormat("<a>{0}</a>\n", HttpUtility.HtmlEncode(user.Company));

There is also the inverse way using HttpUtility.HtmlDecode(string).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to convert string into HTML string?

From Dev

How to convert the String to html

From Dev

NSURL not convert safe string

From Dev

How to convert string to HTML friendly string

From Dev

Kotlin : how to Convert String with HTML numbers to String without HTML numbers

From Dev

How to Convert a Javascript Var Holding Html Into a String?

From Dev

How to convert local HTML file into String?

From Dev

how convert html tags into string in php

From Dev

How to convert string with html encoding to Unicode in java

From Dev

How to convert string to HTML codes in php laravel?

From Dev

How to convert Html to String in Android Java?

From Dev

How to convert HtmlPage into Html string in HtmlUnit

From Dev

how convert html tags into string in php

From Dev

How to convert Chinese Html String into NSString

From Dev

Safe convert from string to date in Transact

From Dev

Safe convert from string to date in Transact

From Dev

How to convert Spannable String into Html formatted String in Android?

From Dev

How to convert Spannable String into Html formatted String in Android?

From Dev

How to convert given html string to normal string android?

From Dev

Convert HTML string to image

From Dev

convert html tags to string

From Dev

Convert string to html attributes

From Dev

jquery convert html to string and to html

From Dev

How to Convert arraylist<string> to string[]

From Dev

ScalaJS: How to convert String to String?

From Dev

How to convert Optional String to String

From Dev

ScalaJS: How to convert String to String?

From Dev

PHP: How to convert ASCII to HTML or how to decode string

From Dev

How to convert a string to BSON?

Related Related

HotTag

Archive