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