Check I.P on hosted server

protected bool chkIP(string videoID)
{
string clientIPAddress = Request.ServerVariables["remote_addr"];
string strVideoId = videoID;

HttpCookie chkcookie = Request.Cookies[clientIPAddress];
HttpCookie chkVideoIdcookie = Request.Cookies[videoID];
//Create the cookie I.P Address
if ((chkcookie != null && chkVideoIdcookie != null) && (Convert.ToString(chkcookie.Value) == clientIPAddress && Convert.ToString(chkVideoIdcookie.Value) == strVideoId))
{
return false;

}
else
{
HttpCookie cookie = new HttpCookie(clientIPAddress);
//Set the cookies value
cookie.Value = clientIPAddress;
//Create the cookie I.P Address
HttpCookie videoIdcookie = new HttpCookie(videoID);
//Set the cookies value
videoIdcookie.Value = videoID;

//Set the cookie to expire in 1 minute
DateTime dtNow = DateTime.Now;
TimeSpan tsMinute = new TimeSpan(0, 0, 1, 0);
//cookie.Expires = dtNow + tsMinute;
cookie.Expires = DateTime.Now.AddMinutes(100000);
videoIdcookie.Expires = DateTime.Now.AddMinutes(100000);

//Add the cookie
Response.Cookies.Add(cookie);
Response.Cookies.Add(videoIdcookie);

return true;
}
}

Comments