Friday, June 19, 2009

Converting a normal IP Address to IP Long/decimal Format

public long ip2long(string ip)
{
string[] parts = ip.Split('.');
string strhexip = string.Format("{0:X2}{1:X2}{2:X2}{3:X2}",
int.Parse(parts[0]), int.Parse(parts[1]),
int.Parse(parts[2]), int.Parse(parts[3]));
return Convert.ToInt64(strhexip, 16);
}

Read IP address of visitor

string ip = Request.ServerVariables["REMOTE_ADDR"];

Turn off cookies for one page in your site

Cookie.Discard Property which Gets or sets the discard flag set by the server