3
Answers

Cookies

jinwolf

jinwolf

20y
2.5k
1
I have tried to search the forum but the search is either not working or the topic is not covered. I have to detect whether or not cookies are allowed. At the moment I am using "Request.Browser.Cookies", but this doesn't do anything. See Below: if(Request.Browser.Cookies==true) { // Read the Cookie; } else { // Tell the user they need cookies enabled; } This is not giving me the desired effect, can someone tell me the correct way to do this or tell me where I can find this information. Thanks
Answers (3)
0
jinwolf

jinwolf

NA 176 0 20y
My method is wrong, that only finds out if the browser is capable of handling cookies. To find out if cookies are enabled you have to write a cookie then read it back, if they are disabled you recieve nothing back because you have written nothing. e.g. HttpCookie MyCookie = new HttpCookie("test"); MyCookie.Value = "test"; MyCookie.Expires = DateTime.Now; Page.Response.Cookies.Add(MyCookie); HttpCookie myCookieRead = new HttpCookie("test"); myCookieRead = Page.Request.Cookies["test"]; // Read the cookie information and display it. if (myCookieRead != null) return true; else return false; Thanks for the help given on this.
0
jinwolf

jinwolf

NA 176 0 20y
Cookieless is false. It just doesn't seem to matter what I do I get the same problem. The application thinks cookies are allowed.
0
nick 0

nick 0

NA 37 0 20y
That is the correct way to do it. Did you change the value of cookieless in the sessionState xml value. check your web.config under sessionState. cookieless="false"