Check For Cookies

R

rn5a

A ASP.NET page checks for the existence of a cookie in the Page_Load
sub:

Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
Dim strUserName As String
Dim ckUserName As HttpCookie
Dim faTicket As FormsAuthenticationTicket

If (Request.Cookies("DomainCookie") IsNot Nothing) Then
ckUserName = Request.Cookies("DomainCookie")
faTicket = FormsAuthentication.Decrypt(ckUserName.Value)
strUserName = faTicket.Name
End If
End Sub

When I run the above code in my local intranet IIS5.1 server in WinXP
Pro (SP2), the If condition doesn't generate any error but when I
upload the above ASP.NET file to a remote hosting server, the If
condition generates the following error:

Value of type 'System.Web.HttpCookie' cannot be converted to
'Boolean'.

which points to the If condition in the above code.

Can someone please throw some light on why is this happening? Why does
the above code snippet generate the above error when I upload the
ASP.NET file to a remote server though it works perfectly fine when I
run the same code snippet in my local Intranet server?
 
G

Guest

A ASP.NET page checks for the existence of a cookie in the Page_Load
sub:

Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
Dim strUserName As String
Dim ckUserName As HttpCookie
Dim faTicket As FormsAuthenticationTicket

If (Request.Cookies("DomainCookie") IsNot Nothing) Then
ckUserName = Request.Cookies("DomainCookie")
faTicket = FormsAuthentication.Decrypt(ckUserName.Value)
strUserName = faTicket.Name
End If
End Sub

When I run the above code in my local intranet IIS5.1 server in WinXP
Pro (SP2), the If condition doesn't generate any error but when I
upload the above ASP.NET file to a remote hosting server, the If
condition generates the following error:

Value of type 'System.Web.HttpCookie' cannot be converted to
'Boolean'.

which points to the If condition in the above code.

Can someone please throw some light on why is this happening? Why does
the above code snippet generate the above error when I upload the
ASP.NET file to a remote server though it works perfectly fine when I
run the same code snippet in my local Intranet server?

I think isNot is new operator in .NET 2. Do you have the same
Framework version on your remote server?

Try to replace

If (Not Request.Cookies("DomainCookie") Is Nothing) Then
 
R

rn5a

I think isNot is new operator in .NET 2. Do you have the same
Framework version on your remote server?

Try to replace

If (Not Request.Cookies("DomainCookie") Is Nothing) Then- Hide quoted text -

- Show quoted text -

Thanks Alex, that indeed was the problem. Your suggestion took care of
the problem. I guess they don't have support for .NET2.0.

Thanks once again,

Regards,

RON
 

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

Similar Threads

Cookies 1
Cookies 1
Way to check for cookies 4
Cookies during error handling 1
Cookies Count 2
Clearing cookies 2
Cookies special characters. 1
Problem with accessing cookies? 3

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top