473,410 Members | 1,872 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,410 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 1620

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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.