Sql injection saldırıyla yoluyla veritabanı kayıtları okunabiliyor hatta veritabanlarına müdahele edilebiliyor.İşte vb.net ile yazılmış asp.net sql saldırılarına karşı koruma önlemlerini içeren kod:default.aspx dosyası
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="sqlinjection.aspx.vb" Inherits="sqlinjection" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="adsoyad" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="tıkla" />
</form>
</body>
</html>default.aspx.vb dosyası
Partial Class sqlinjection
Inherits System.Web.UI.Page
Public Function clear(ByVal temizle As String) As String
temizle = temizle.Replace("'", "tek tırnak")
temizle = temizle.Replace("--", "")
temizle = temizle.Replace("/*", "")
temizle = temizle.Replace("*/", "")
temizle = temizle.Replace(";", "a")
temizle = temizle.Replace("drop", "drp")
temizle = temizle.Replace("DROP", "DRP")
temizle = temizle.Replace("alter", "altr")
temizle = temizle.Replace("ALTER", "AltR")
temizle = temizle.Replace("Update", "upd")
Return temizle
End Function
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = clear(adsoyad.Text)
End Sub
End Classsql injection koruma önlemi almak istediğiniz textbox kutusuna clear(textbox.text) gibi önlem almanız yetrlidir.güle güle kullanın.Arama yaptım görmedim ama daha önce bu konu açıldıysa kusura bakmayın.