I am testing to see whether the user has cookies turned on and I don't seem to be doing something right.
Here is my test:
private bool CookiesAllowed()
{
var testCookie = new HttpCookie("TestCookie", "abcd");
System.Web.HttpContext.Current.Response.Cookies.Set(testCookie);
var tst = System.Web.HttpContext.Current.Request.Cookies.Get("TestCookie");
if (tst == null || tst.Value == null)
{
return false;
}
return true;
}
I'm putting a cookie out there... and then getting it back. But it always succeeds.
Here is how I'm disabling them:
I go to Gmail and it tells me my cookies are disabled so I believe I am doing that part right.
What am I doing wrong?
EDIT
To answer James' question, I am calling this from my logon screen, which is my entry screen as the first check:
public ActionResult LogOn(string id)
{
if (!CookiesAllowed())
{
return View("CookiesNotEnabled");
}
Also, I have tested this live, outside of visual studio and not at localhost and it did the same thing.