From a quick search on Stack Overflow I saw people suggesting the following way of checking if a cookie exists:
HttpContext.Current.Response.Cookies["cookie_name"] != null
or (inside a Page
class):
this.Response.Cookies["cookie_name"] != null
However, when I try to use the indexer (or the Cookies.Get method) to retrieve a cookie that does not exist it seems to actually create a 'default' cookie with that name and return that, thus no matter what cookie name I use it never returns null. (and even worse - creates an unwanted cookie)
Am I doing something wrong here, or is there a different way of simply checking for the existance of a specific cookie by name?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…