Problem with detecting cookie

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>
 
G

Guest

You are using OR in you logic. Clearly, cookie "try" does not exist and
that's why you will always be redirected.
 
G

Guest

I do not want to redirect user if one of the two cookies exist. This is why I
am using OR.
 
G

Guest

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>
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top