Click here to Skip to main content
15,896,278 members
Articles / Web Development / ASP.NET

SQL Injection and Cross-Site Scripting

Rate me:
Please Sign up or sign in to vote.
4.92/5 (144 votes)
17 Apr 2017CPOL14 min read 501.7K   3.9K   317  
An article on SQL Injection and Cross-Site Scripting with sample code in C#.
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

public partial class JavaScriptFunctionInjection : System.Web.UI.Page
{
    public string sValue = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void Button2_Click(Object sender, CommandEventArgs e)
    {
        string formValue = Request.Form["Text1"] as string;
        string formValue2 = Request.Form["Text2"] as string;

        if (e.CommandArgument == "single")
        {

            if (!string.IsNullOrEmpty(formValue))
            {
                sValue = Server.HtmlEncode(formValue.Replace("'", "''"));
            }
        }
        else
        {
            if (!string.IsNullOrEmpty(formValue2))
            {
                sValue = formValue2; //quote
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
I have over 10 years of experience working with Microsoft technologies. I have earned my Microsoft Certified Technology Specialist (MCTS) certification. I'm a highly motivated self-starter with an aptitude for learning new skills quickly.

Comments and Discussions