Problem with detecting cookie

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a asp.net page that checks if any one of the two cookies exists. If
none of the cookies exist then redirect the user to login page.
Cookie “try†doesn’t exists. I can see that cookie “mode†exist, but for
some reason the following code fails to detect it and keeps redirecting user
to login.aspx page which it shouldn’t because the cookie “mode†exists

Can someone tell me what could be the problem?

Thanks for your help

Joe


<script runat="server">
Sub page_load(S as Object, e as EventArgs)
If (Request.Cookies("try") Is Nothing ) or (Request.Cookies("mode") Is
Nothing ) Then
Response.Redirect("login.aspx")
End If
End Sub
</script>
 
You are using OR in you logic. Clearly, cookie "try" does not exist and
that's why you will always be redirected.
 
I do not want to redirect user if one of the two cookies exist. This is why I
am using OR.
 
That's why you should use AND instead of OR. Like this:

<script runat="server">
Sub page_load(S as Object, e as EventArgs)
If (Request.Cookies("try") Is Nothing ) and (Request.Cookies("mode") Is
Nothing ) Then
Response.Redirect("login.aspx")
End If
End Sub
</script>
 
Tried your code. It works fine when cookie "try" exists, but fails when
cookie "mode" exists. I can see that cookie "mode" exists still your code
redirects the user to login.aspx page which it shouldn't.

I never thought that checking two cookies will be so hard.

Joe
 
Back
Top