Here, I have to show the example how to
restrict SQL injection.
HTML markup: Add this markup in default.aspx source(HTML) part.
<table width="50%" align="center" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="30%">
<asp:textbox id="txtName" runat="server" />
</td>
<td>
<asp:button id="btnSave" runat="server" text="Save" onclick="btnSave_Click" />
<asp:label id="lblMesg" runat="server" text="Label"></asp:label>
</td>
</tr>
</table>
Code behind Code
Add this code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class frmSQLinjection : System.Web.UI.Page
{
public static SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=studentdetail;Integrated security=true");
protected void Page_Load(object sender, EventArgs e)
{
}
After that the add checkForSQLInjection method in the code behind=>this method
check the Input string against the SQL injection. Here I have to list all SQL
injection input in array of string. Adding this method returns true and false.
public static Boolean checkForSQLInjection(string userInput)
{
bool isSQLInjection = false;
string[] sqlCheckList = { "--",
";--",
";",
"/*",
"*/",

Join the conversation! Your thoughts help the community grow.