checking for enabled cookies?

J

Jeff

I have a vb.net application (2005) requiring session variables and want to
test to make certain that the user's cookies are enabled.

I can set a test session variable on one page and attempt to read it on the
next with the code below in order to determine if the user has their
browser's cookies enabled, but is there a good way to do this on the
first/default page without a redirect to another page that will actually do
the test?

Thanks
Jeff


'On first page
Session("CookiesEnabled") = True


'On second page
If Not AreCookiesEnabled() = True Then
Response.Redirect("~\CookieError.aspx")
End If

Public Function AreCookiesEnabled() As Boolean
On Error GoTo A
If Session("CookiesEnabled") = True Then
Return True
End If
A: Return False
End Function
 
L

Luke Zhang [MSFT]

Hello Jeff,

Your way is already the regular way we check if a client supports cookies.
This is also discussed in this article:

Basics of Cookies in ASP.NET
http://msdn2.microsoft.com/en-us/library/aa289495(VS.71).aspx

You may check the section of "Checking Whether a Browser Accepts Cookies",
it uses a similiar way. Also there is a lot about cookies in this article,
hope this help.

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Well i would modify the code to this

'On first page
Session("CookiesEnabled") = True


'On second page
If Not AreCookiesEnabled() Then
Response.Redirect("~\CookieError.aspx")
End If

Public Function AreCookiesEnabled() As Boolean
try
If cbool(Session("CookiesEnabled")) Then Return True
catch ex as exception
return false
end try
End Function
 
J

Jeff

Luke Zhang said:
Hello Jeff,

Your way is already the regular way we check if a client supports cookies.
This is also discussed in this article:

Basics of Cookies in ASP.NET
http://msdn2.microsoft.com/en-us/library/aa289495(VS.71).aspx

You may check the section of "Checking Whether a Browser Accepts Cookies",
it uses a similiar way. Also there is a lot about cookies in this article,
hope this help.

Sincerely,

Luke Zhang

The code and flow of the pages in site above looks like what I'm looking for
my specific problem.

Thanks (and to Michel also)

Jeff
 

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

Top