سلام ببین این به کارت میاد :
if (blockMode == Poll.BlockMode.COOKIE.ToString()) //If block by Cookie read the cookie to see if there is an entry for this blog
{
if (Request.Cookies["Poll"] != null && Request.Cookies["Poll"]["ID"] != null)
{
//the cookie will have comma seperated IDs of all the polls that already voted
string commaSeperatedPollIDs = Request.Cookies["Poll"]["ID"];
//split it with comma
string[] pollIDs = commaSeperatedPollIDs.Split(",".ToCharArray());
//and loop through each pollID to find whethere the current poll is already voted
foreach (string pID in pollIDs)
{
//if yes break
if (pID == hidPollID.Value)
{
isPolled = true;
break;
}
}
//Save the poll ID in cookie - to block repeated vote if the BlockMode is by Cookie
HttpCookie pollCookie;// = new HttpCookie("Poll");
string valueToStore = ""; //we store the poll IDs as comma seperated values
//the cookie already exists and some PollIDs are already there
if (HttpContext.Current.Request.Cookies["Poll"] != null && HttpContext.Current.Request.Cookies["Poll"]["ID"] != null)
{
pollCookie = HttpContext.Current.Request.Cookies["Poll"];
valueToStore = HttpContext.Current.Request.Cookies["Poll"]["ID"] + "," + pID.ToString(); //append the current PollID to the already existing Poll IDs after a comma
}
else//cookie not exists - create a new one and store the ID
{
pollCookie = newHttpCookie("Poll");
valueToStore = pID.ToString();
}
pollCookie.Values["ID"] = valueToStore;
pollCookie.Expires = DateTime.MaxValue; //this cookie will never expire
HttpContext.Current.Response.Cookies.Add(pollCookie);