I am using cookies to know whether a page was loaded before or not. So in page load of a asp.net c# page I am using this
if (Request.Cookies["PageLoaded"] == null)
{
//Initialize things if page loading for first time.
}
and inside the if as last parameter I am setting the cookies value like given below
if (Request.Cookies["PageLoaded"] == null)
{
//Initialize things if page loading for first time.
//Set cookies value to indicate page has loaded before
Response.Cookies["PageLoaded"].Value = "True";
}
When I run in local host its working fine. But when I host it to server for each page load(Postback events) the initial if statement is true(ie cookie is always null) and going inside the loop.
Am I doing something wrong? How can I do this in c#? Thanks