SQL Injection for beginners

When we talk about security vulnerabilities in software it’s worth thinking about computer programmes on a fundamental level. On the simplistic level a computer programme is something which takes in an input, usually from the user in the form of text, processes that input, which changes the state of the machine, and then gives as output or result to the user. A bug is when certain inputs aren’t processed correctly and the wrong output is given. For example, if 1 plus 1 results in 3. A security bug however, can be when a certain input is processed in such a way that compromises the security of information managed by a programme and may even output it. We often see this in practice in web applications. Continue reading “SQL Injection for beginners”

Using the configuration Builder in ASP.NET 5

The Problem

Managing the configuration data have always been troublsome. Although Microsoft did provided and also updated/upgraded a lot of options from time to time, yet it remains  a challenge most of time. Things get more critical when the configuration data we are concerned is the confidential data like connection string, smtp passwords, API keys etc becase at some point of time, they do get checked in source code or shared across other developers. In one of my prev project faced a similar issue when private key and the Code Signing certificate was accidentally checked in by a developer. The customer had to revoke the certificate which invalidated all the production builds which were deployed to end users as well. Continue reading “Using the configuration Builder in ASP.NET 5”

Using ASMX webservices with HttpWebRequest in c# 4.0

If you want to call a .NET 4.0 C# web service, without using the WSDL or “Add Service Reference” in Microsoft Visual Studio 2015, you can use the following functions written in c#:

/// <summary>
/// Execute a Soap WebService call
/// </summary>
public override void Execute()
HttpWebRequest request = CreateWebRequest();
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<HelloWorld3 xmlns=""http://tempuri.org/"">
using (Stream stream = request.GetRequestStream()) 
using (WebResponse response = request.GetResponse())
using (StreamReader rd = new StreamReader(response.GetResponseStream())) 
string soapResult = rd.ReadToEnd();
/// <summary>
/// Create a soap webrequest to [Url]
/// </summary>
/// <returns></returns>
public HttpWebRequest CreateWebRequest()
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"http://dev.nl/Rvl.Demo.TestWcfServiceApplication/SoapWebService.asmx"); 
webRequest.ContentType = "text/xml;charset=\"utf-8\""; 
webRequest.Accept = "text/xml"; 
webRequest.Method = "POST"; 
return webRequest; 


<?xml version=”1.0″ encoding=”utf-8″?><soap:Envelope xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema”><soap:Body><HelloWorld3Response xmlns=”http://tempuri.org/”><HelloWorld3Result>test</HelloWorld3Result></HelloWorld3Response></soap:Body></soap:Envelope>


You can use complex types in you’re request. I use fiddler to get the contents of the soap envelope.

How to remove the empty rows in a DataTable using vb.net and one line of code.

Here’s a challenge for you. Using only one line of code, remove all the empty lines in a data table.

Empty is defined by a Null value or an empty string (/whitespace).

DataTableObject = DataTableObject.Rows.Cast(Of DataRow)().Where(Function(row) Not row.ItemArray.All(Function(field) TypeOf field Is System.DBNull OrElse String.Compare(TryCast(field, String).Trim(), String.Empty) = 0)).CopyToDataTable()

Retrieving Excel data using EPPlus with and without headers

If you ever had to read from a sheet inside C# using EPPlus, you can use the following snippet to read the data.

EPPlus is a .net library that reads and writes Excel 2007/2010 files using the Open Office Xml format (xlsx).


using OfficeOpenXml;
string sourceFilePath = hidFilename.Value;
            using (ExcelPackage package = new ExcelPackage(new FileInfo(sourceFilePath)))
                ExcelWorksheet ws = package.Workbook.Worksheets[ddlSheets.SelectedItem.Text];
                DataTable tbl = new DataTable();
                var hasHeader = chkHasHeaders.Checked;
                foreach (var firstRowCell in ws.Cells[1, 1, 1, ws.Dimension.End.Column])
                    string strColumnName = hasHeader
                        ? firstRowCell.Text
                        : string.Format("Column {0}", firstRowCell.Start.Column);
                    int counts = 0;
                    string newColumn = strColumnName;
                    while (tbl.Columns.Contains(newColumn))
                        newColumn = strColumnName + counts.ToString();
                var startRow = hasHeader ? 2 : 1;
                for (var rowNum = startRow; rowNum <= ws.Dimension.End.Row; rowNum++)
                    var wsRow = ws.Cells[rowNum, 1, rowNum, ws.Dimension.End.Column];
                    var row = tbl.NewRow();
                    foreach (var cell in wsRow)
                        row[cell.Start.Column - 1] = cell.Text;
                grdTable.DataSource = tbl;

Code to copy content to clipboard

  Private _val As String
    Public Property Val() As String
            Return _val
        End Get
        Set(ByVal value As String)
            _val = value
        End Set
    End Property

    Protected Sub ClipboardBtn_Click(sender As Object, e As EventArgs)
        Val = sender.CommandArgument
        Dim staThread As Thread = New Thread(New ThreadStart(AddressOf myMethod))
    End Sub

If this is working for Windows Forms Applications, you can use the following in IE to copy text:

holdtext.innerText = copytext.innerText;
Copied = holdtext.createTextRange();