By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,372 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

Problem with detecting cookie

P: n/a
Joe
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>

Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
You are using OR in you logic. Clearly, cookie "try" does not exist and
that's why you will always be redirected.
--
Tu-Thach
"Joe" wrote:
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>

Nov 19 '05 #2

P: n/a
Joe
I do not want to redirect user if one of the two cookies exist. This is why I
am using OR.

"Tu-Thach" wrote:
You are using OR in you logic. Clearly, cookie "try" does not exist and
that's why you will always be redirected.
--
Tu-Thach
"Joe" wrote:
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>

Nov 19 '05 #3

P: n/a
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>
--
Tu-Thach
"Joe" wrote:
I do not want to redirect user if one of the two cookies exist. This is why I
am using OR.

"Tu-Thach" wrote:
You are using OR in you logic. Clearly, cookie "try" does not exist and
that's why you will always be redirected.
--
Tu-Thach
"Joe" wrote:
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>

Nov 19 '05 #4

P: n/a
Joe
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

"Tu-Thach" wrote:
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>
--
Tu-Thach
"Joe" wrote:
I do not want to redirect user if one of the two cookies exist. This is why I
am using OR.

"Tu-Thach" wrote:
You are using OR in you logic. Clearly, cookie "try" does not exist and
that's why you will always be redirected.
--
Tu-Thach
"Joe" wrote:

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

Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.