Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Html.Encode in webforms

Tags:

I have an ASP.NET Web Forms application. There is a page with TextBoxes and users enter search terms into these which are used to query the database.

I know that I need to prevent JavaScript injection attacks. How do I do this?

In MVC I would use Html.Encode. It doesn't seem to be recognized in Web Forms.

Thanks!

like image 997
Mr Cricket Avatar asked Oct 25 '10 21:10

Mr Cricket


People also ask

How do I encode HTML?

Load the data to HTML–encode from a file, then press the 'Encode' button: Browse: Alternatively, type or paste in the text you want to HTML–encode, then press the 'Encode' button.

What is HTML encoding C#?

HtmlEncode(Object)Converts an object's string representation into an HTML-encoded string, and returns the encoded string. public: static System::String ^ HtmlEncode(System::Object ^ value); C# Copy.

What is the use of HTML encode?

HTML encoding makes sure that text is displayed correctly in the browser and not interpreted by the browser as HTML.

When should I use HtmlEncode?

Any time you are trying to output data that could include untrusted html, you should use HTMLENCODE . Encodes text and merge field values for use in HTML by replacing characters that are reserved in HTML, such as the greater-than sign ( > ), with HTML entity equivalents, such as > .


1 Answers

You can use HttpUtility.HtmlEncode

like image 190
Badaro Avatar answered Oct 07 '22 19:10

Badaro