Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you can't filter the Textbox, you have to filter the data in the Postback .</p> <ul> <li>Use <strong>Server.HtmlEncode(your text here)</strong> to Escape characters normally used for SQL Injection :</li> </ul> <blockquote> <p>string userInput = @"' or 1=1; -- ";</p> <p>string encodedString = Server.HtmlEncode(userInput);</p> </blockquote> <p>the result will be :</p> <pre><code>&amp;#39; or 1=1; -- &amp;lt;html&amp;gt; </code></pre> <ul> <li>Use Regex to replace invalid characters with space or anything to indicate that the characters was replaced (use *) :</li> </ul> <blockquote> <pre><code>Regex myRegex = new Regex("[\\\'\\\"\\&lt;\\&gt;=]", RegexOptions.Compiled | RegexOptions.IgnoreCase); string userInput = @"' or 1=1; -- &lt;html&gt;"; string encodedString = myRegex.Replace(userInput, ""); </code></pre> </blockquote> <p>the result will be :</p> <blockquote> <p>or 11; -- html</p> </blockquote> <ul> <li>Use parameters in your SQL queries and validate the values before add the</li> </ul> <blockquote> <p>using (SqlConnection cn = new SqlConnection("Your Connection string here")) {</p> <pre><code> using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = cn; cmd.CommandType = CommandType.Text; cmd.CommandText = "Select * From [User] Where (UserName = @UserName AND Password = @Password)"; cmd.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = Server.HtmlEncode(txtUserName.Text); cmd.Parameters.Add("@Password", SqlDbType.NVarChar).Value = Server.HtmlEncode(txtPassword.Text); cn.Open(); IDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { // Your code here } } } </code></pre> </blockquote> <ul> <li>There is custom controls ready to use with options to control what the user can enter in specified text box .</li> <li>Last advice in Web programming you have to double check (1- Client side using JavaScript) and (2- Server side using your own rules of doubts and concerns).</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload