ASP.Net - A potentially dangerous Request.Form value was detected from the client Code Example

The code for A potentially dangerous Request.Form value was detected from the client

// The exception occurred when any input text has some special characters 
// like less than (<), greater than (>), single quote ('), etc.

// Make the changes on both of the pages (asp) and code behind (on_load)

// Before closing </asp:content>, insert this JS
<script language="javascript" type="text/javascript">
    function encodeMyHtml(toEncode) {
        return toEncode.replace(/&/gi, '&amp;').replace(/\"/gi, '&quot;').replace(/</gi, '&lt;').replace(/>/gi, '&gt;');
    }
</script>

' on_load (Bind those input boxes) - vb code
BtnCodeSubmit.Attributes.Add(
    "onclick",
    "this.form." + TxtName.ClientID + ".value = encodeMyHtml(this.form." + TxtName.ClientID + ".value);"
)
Code by IncludeHelp, on August 11, 2022 23:20

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.