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