I. One method
/// <Summary>
/// SQL Injection Filtering
/// </Summary>
/// <Param name = "InText"> string to be filtered </param>
/// <Returns> If the parameter contains insecure characters, true is returned. </returns>
Public static bool SqlFilter2 (string InText)
{
String word = "and | exec | insert | select | delete | update | chr | mid | master | or | truncate | char | declare | join | '";
If (InText = null)
Return false;
Foreach (string str_t in word. Split ('| '))
{
If (InText. toLower (). indexOf (str_t + "")>-1) | (InText. toLower (). indexOf ("" + str_t)>-1) | (InText. toLower (). indexOf (str_t)>-1 ))
{
Return true;
}
}
Return false;
}
2. A method in global. ascx
/// <Summary>
/// Trigger an event when data is handed in
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Protected void Application_BeginRequest (Object sender, EventArgs e)
{
// Traverse the Post parameter, except for hidden fields
Foreach (string str_t in this. Request. Form)
{
If (str_t = "_ VIEWSTATE") continue;
This. goErr (this. Request. Form [str_t]. ToString ());
}
// Traverse Get parameters.
Foreach (string str_t in this. Request. QueryString)
{
This. goErr (this. Request. QueryString [str_t]. ToString ());
}
}
3. Another method in global. asax
/// <Summary>
/// Check whether the parameter contains SQL characters
/// </Summary>
/// <Param name = "tm"> </param>
Private void goErr (string tm)
{
If (wenlong. function. func. SqlFilter2 (tm ))
This. Response. Redirect ("/error ");
// Response. Redirect ();
}