473,566 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_testCooki e") Is Nothing Then
Response.Cookie s("sys_testCook ie").Value = True
Response.Cookie s("sys_testCook ie").Expires =
DateTime.Now.Ad dMinutes(3)

Response.Redire ct("/Engines/System/Sys_CookieTest. aspx?redirect=" &
Server.UrlEncod e(Request.Url.T oString))
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.EventArg s) Handles

MyBase.Load

If Not IsPostBack Then

Dim Redirect As String =
CStr(Request.Qu eryString("redi rect"))
Dim QueryString As String = ""

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

' Was the cookie accepted?
If Request.Cookies ("sys_testCooki e") 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.IndexO f("?")
If index = -1 Then
QueryString = "?AcceptCookies =False"
Else
QueryString = "&AcceptCookies =False"
End If

Response.Redire ct(Redirect & QueryString)

Else

If Not Request.QuerySt ring("AcceptCoo kies") =
"False" Then
Response.Cookie s("sys_testCook ie").Value =
True
Response.Cookie s("sys_testCook ie").Expires
=

DateTime.Now.Ad dMinutes(3)

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

Server.UrlEncod e(Request.Url.T oString), True)
End If

End If

Else

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

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

End If

End Sub

Nov 22 '05 #1
0 1650

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

Similar topics

2
1776
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") 'if cookie hasn't already been set, then set it! If cookieValue = "" Then
11
2441
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 this JavaScript below to enable this ? if (document.form1.EMAIL.value == ""){ alert("Please complete the E-Mail: field")...
0
333
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: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchaspnetcookies101.asp under section: 'Checking Whether a Browser Accepts Cookies' This code works great, when its...
2
2014
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 in .net as it did in old asp but for some reason I'm getting "System.NullReferenceException: Object reference not set to an instance of an object"...
3
1350
by: Ollie | last post by:
Can you check whether a users browser allows you to use cookies? Cheers Ollie
9
3053
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 application, how can we code the project to check to make sure the browser accepts cookies? 2. Where would we put this code? In Global.asax? 3. ...
1
1107
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
2412
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How can I see in javascript if a web browser accepts cookies? ----------------------------------------------------------------------- Writing a cookie, reading it back and checking if it's the same. http://www.w3schools.com/js/js_cookies.asp Additional...
4
4038
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 read it on the next with the code below in order to determine if the user has their browser's cookies enabled, but is there a good way to do this on...
5
4108
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 key-value pairs) in a cookie on the user's computer, and it should be
0
7666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7644
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.