Tag Archives: C#
Get the IP address in ASP.NET
To get the ip address of client machine in asp.net use the following code snippet. private string GetUserIP() { string ip = Request.ServerVariables["HTTP_X_CLUSTER_CLIENT_IP"]; string trueIP = string.Empty; if (!string.IsNullOrEmpty(ip)) {… Read more
Validating Facebook cookie for current logged in user
Here is a small class in C# to validate the Facebook cookie (fbsr_APPID) Here I have used Jayrock’s json C# library to handle the json strings in C#. public string… Read more
Remove non-alphanumeric characters from the string C#
To remove the non-alphanumeric characters from the string using C#, what one thought would be to iterate the characters and check the charcode if it is in range then append… Read more
A String quiz in C#
How many string objects the below method will create? string GeneratePhrase() { string phrase = “”; Random rnd = new Random(); for (int i = 0; i < 1000; i++)… Read more
Get Images from a web page C#
There are few things we might need to consider while extracting images from a webpage. what all images do we want from webpage, i.e., images with alt and title tag…. Read more
Read excel file using ACE OLE DB in C#
To read an excel file in C# using ACE OLE DB. first install the ACE OLE DB component from the following link http://www.microsoft.com/en-us/download/details.aspx?id=13255. First get the work sheet name from… Read more
Filter to search Active Directory using first name and last name in C#
I took a lot of time to figure out, how to search the AD using first name and last name. DirectorySearcher search = new DirectorySearcher( new DirectoryEntry(LDAP_CONNECTION_STRING, LDAP_DOMAIN + @”\”… Read more
Secured cookie based authentication in C#
Recently I have written a C# class for cookie based authentication in one of our projects. public class ValidateModule { public static string sharedSecret = ConfigValues.SharedSecret; private static byte[] _salt… Read more
Program to find Anagrams
An anagram of a word or phrase is the result of rearranging its letters to form another meaningful word or phrase. For example, an anagram of “anagram finder” is “garden… Read more