Asp.net anti-SQL Injection

Source: Internet
Author: User

I. Verification Method

 

/// / <Summary>
/// SQL Injection Filtering
///   </Summary>
///   <Param name = "intext"> String to be filtered </Param>
///   <Returns> Returns true if the parameter contains insecure characters. </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 I In Word. Split ( ' | ' ))
{
If (Intext. tolower (). indexof (I + "   " ) >- 1 ) | (Intext. tolower (). indexof ( "   " + I) >- 1 ))
{
Return   True ;
}
}
Return   False ;
}

 

2. Global. asax event

 

/// / <Summary>
/// An event is triggered when data is handed in.
///   </Summary>
///   <Param name = "sender"> </param>
///   <Param name = "E"> </param>
Protected   Void Application_beginrequest (Object sender, eventargs E)
{
// Traverse post parameters, except for hidden fields
Foreach ( String I In   This . Request. Form)
{
If (I = " _ Viewstate " ) Continue ;
This . Goerr ( This . Request. Form [I]. tostring ());
}
// Traverse get parameters.
Foreach ( String I In   This . Request. querystring)
{
This . Goerr ( This . Request. querystring [I]. tostring ());
}
}

3. A method in global

 

///   <Summary>
/// Check whether the parameter contains SQL characters
///   </Summary>
///   <Param name = "TM"> </param>
Private   Void Goerr ( String TM)
{
If (Wlcw. Extend. cvalidity. sqlfilter2 (TM ))
This . Response. Redirect ( " /Error.html " );
}

TheArticleReproduced from Taipa studio: http://www.dezai.cn/article_show.asp? ArticleID = 18624

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.