asp.net most powerful SQL anti-injection code

Source: Internet
Author: User
Tags httpcontext


SqlConnection conn = new Sqlcheck (). oconn ();
The 2nd method of Invocation sqlcheck.jk1986_checksql ();
string osql = "SELECT COUNT (*) from admin";
SqlCommand ocmd = new SqlCommand (osql, Conn);

Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.Data.SqlClient;
<summary>
Summary description of Sqlcheck
</summary>

//#region, #endregion to be more aesthetically pleasing to the VS code display, capable of folding and expanding                       
public class Sqlcheck
{
 public Sqlcheck ()
 {
  //
  //TODO: Add constructor logic here
  //  
   }

   
    public SqlConnection oconn ()
    {
  & nbsp;     SqlConnection conn = new SqlConnection ();
        Conn. ConnectionString = configurationmanager.connectionstrings["studyconnectionstring"]. ToString ();
       //1th method of Invocation    jk1986_checksql ();
        jk1986_checksql ();
        if (conn. state = = connectionstate.closed )
        {
             Conn. Open ();
       }
        return conn;
   }


Public DataTable GetSource (string Getds)
{
SqlConnection conn = oconn ();
SqlDataAdapter da = new SqlDataAdapter (GETDS, Conn);
DataSet ds = new DataSet ();
Da. Fill (ds, "News");
Return DS. tables["News"];
}

public static void Jk1986_checksql ()
{
String jk1986_sql = "Exec↓select↓drop↓alter↓exists↓union↓and↓or↓xor↓order↓mid↓asc↓execute↓xp_ Cmdshell↓insert↓update↓delete↓join↓declare↓char↓sp_oacreate↓wscript.shell↓xp_regwrite↓ ' ↓;↓--';
string[] Jk_sql = Jk1986_sql. Split (' ↓ ');
foreach (String jk in Jk_sql)
{
-----------------------Anti Post injection-----------------------
if (System.Web.HttpContext.Current.Request.Form!= null)
{
for (int k = 0; k < System.Web.HttpContext.Current.Request.Form.Count; k++)
{
String getsqlkey = System.web.httpcontext.current.request.form.keys[k];
String GetIP;
if (System.web.httpcontext.current.request.form[getsqlkey). ToLower (). Contains (JK) = = True)
{
                        System.Web.HttpContext.Current.Response.Write ("<script Language=javascript>alert" ( ' ASP.net (C # version) anti-injection program prompts you not to submit illegal characters! ↓\n\nblog:http://hi.baidu.com/ahhacker86 \n\nby:

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.