473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Checking Whether a Browser Accepts Cookies

Hi

I have some code for checking for cookies, that sets a cookie on page1
and checks for it on page2. and its based on the code by MS:

http://msdn.microsoft.com/library/de...cookies101.asp

under section: 'Checking Whether a Browser Accepts Cookies'

This code works great, when its in my development enviroment.
But once places on our live server, the cookie check always returns
false.

any ideas?

----- CheckCookie() Code -----
Private Function CheckCookie() As Boolean

If Not Request.Params("AcceptCookies") Is Nothing And
Request.Params("AcceptCookies") <> "" Then

If Request.Params("AcceptCookies") = "False" Then
Return False
End If

Else

If Request.Cookies("sys_testCookie") Is Nothing Then
Response.Cookies("sys_testCookie").Value = True
Response.Cookies("sys_testCookie").Expires =
DateTime.Now.AddMinutes(3)

Response.Redirect("/Engines/System/Sys_CookieTest.aspx?redirect=" &
Server.UrlEncode(Request.Url.ToString))
Else
Return True
End If

End If

End Function

----- end -----

----- Sys_CookieTest.aspx Code ------

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles

MyBase.Load

If Not IsPostBack Then

Dim Redirect As String =
CStr(Request.QueryString("redirect"))
Dim QueryString As String = ""

Response.Write("Checking for cookie...<BR><BR>")

' Was the cookie accepted?
If Request.Cookies("sys_testCookie") Is Nothing Then

' No cookie, so it must not have been accepted
Response.Write("Cookie not found...<BR><BR>")

If Redirect <> "" Then

Dim index As Integer = Redirect.IndexOf("?")
If index = -1 Then
QueryString = "?AcceptCookies=False"
Else
QueryString = "&AcceptCookies=False"
End If

Response.Redirect(Redirect & QueryString)

Else

If Not Request.QueryString("AcceptCookies") =
"False" Then
Response.Cookies("sys_testCookie").Value =
True
Response.Cookies("sys_testCookie").Expires
=

DateTime.Now.AddMinutes(3)

Response.Redirect("/Engines/System/Sys_CookieTest.aspx?redirect=" &

Server.UrlEncode(Request.Url.ToString), True)
End If

End If

Else

Response.Write("Cookie found...<BR><BR>")

If Redirect <> "" Then
Response.Redirect(Redirect)
End If
End If

End If

End Sub

Nov 22 '05 #1
0 1618

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andrew Duffy | last post by:
Hi, I just want to check that i'm not going crazy.. I want to check whether or not a cookie has already been set and so I am using the following code. cookieValue = Request.Cookies("CartID")...
11
by: Phil Amey | last post by:
In a web based form I am able to make sure that there is text in an input field but I want to force the user into inputting a valid email address, one that has @ in the address How can I modify...
0
by: Lucifer | last post by:
Hi I have some code for checking for cookies, that sets a cookie on page1 and checks for it on page2. and its based on the code by MS: ...
2
by: CES | last post by:
I'm sorry for the 101 question but I can't seem to get this to work... I'm tiring to test if a cookie has been created before. Everything I've seen indicates that Request.Cookies works the same...
3
by: Ollie | last post by:
Can you check whether a users browser allows you to use cookies? Cheers Ollie
9
by: SHarris | last post by:
Hello, In our new intranet ASP.NET project, two requirements are that the browser accept cookies AND JavaScript. We are requiring the use of Internet Explorer 6+. 1. Using C# in an ASP.NET...
1
by: Tina | last post by:
When I use Request.Browser.Cookies I always get true returned. Even when the browser has cookie acceptance turned off. Why? Thanks, T
24
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How can I see in javascript if a web browser accepts cookies?...
4
by: Jeff | last post by:
I have a vb.net application (2005) requiring session variables and want to test to make certain that the user's cookies are enabled. I can set a test session variable on one page and attempt to...
5
by: bgold12 | last post by:
When a user logs onto my site, I set some session data using php: .... session_start(); .... $_SESSION = 'value'; .... From what I understand, this should store the session data (i.e. the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.