473,378 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

What is the proper way to use cookies?

This is how I clear all cookies/give cookies/detect cookies

am i doing it the right way?
Somehow or rather, i would hit an object cannot be instanisiated from null
or something whenever it tries to read cookies
Clear cookies:
Response.Cookies.Clear()

Dim ck1 As HttpCookie = Request.Cookies("USERLOGGEDIN")

If Not ck1 Is Nothing Then

Response.Cookies("USERLOGGEDIN").Expires = DateTime.Now.AddDays(-1)

End If

This is how I put in cookies:

If Request.Cookies("USERLOGGEDIN") Is Nothing Then

Dim ck As New HttpCookie("USERLOGGEDIN")

ck.Value = "1"

Response.Cookies.Add(ck)

End If

This is how i detect cookies:

Dim ck1 As HttpCookie = Request.Cookies("USERLOGGEDIN")

If ck1 Is Nothing Then

Response.Redirect("login.aspx")

End If

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Apr 1 '07 #1
1 1366
Code seems ok to me at first glance. Do you have a stack trace of the error?

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"Eric Layman" <namyalcire[at no spam]gmail.comwrote in message
news:11**************@sp6iad.superfeed.net...
This is how I clear all cookies/give cookies/detect cookies

am i doing it the right way?
Somehow or rather, i would hit an object cannot be instanisiated from null
or something whenever it tries to read cookies
Clear cookies:
Response.Cookies.Clear()

Dim ck1 As HttpCookie = Request.Cookies("USERLOGGEDIN")

If Not ck1 Is Nothing Then

Response.Cookies("USERLOGGEDIN").Expires = DateTime.Now.AddDays(-1)

End If

This is how I put in cookies:

If Request.Cookies("USERLOGGEDIN") Is Nothing Then

Dim ck As New HttpCookie("USERLOGGEDIN")

ck.Value = "1"

Response.Cookies.Add(ck)

End If

This is how i detect cookies:

Dim ck1 As HttpCookie = Request.Cookies("USERLOGGEDIN")

If ck1 Is Nothing Then

Response.Redirect("login.aspx")

End If

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Apr 1 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Maverick | last post by:
Hello all, I read some good reviews about jakarta HTTPClient about its session and cookies management system and fancied giving it a try as a learning exercise but somehow I don't seem to be able...
4
by: Brian Burgess | last post by:
Hi all, Anyone know of any special issues with storing cookies with ASP? I'm trying this with two browsers: One is IE 6.0 with cookies set to 'prompt'. This has been working properly as any...
20
by: Brian Burgess | last post by:
Hi all, Anyone know if this is possible? If so, on which page would the cookie be? .. On the page calling a function defined in the include file? thanks in advance.. -BB
2
by: mark4asp | last post by:
Hello, I'm running my script locally and the cookie has been saved on the machine because the login page is by-passed (with the Redirect to "menu.asp" below. OK - but where is my cookie...
1
by: Karl | last post by:
Hi there! I have a big Problem with some Javascript: On a website, i want to paste some "confirm", if the visitor's browserlanguage is not "de". when he confirm, he'll be redirected to the...
8
by: CDARS | last post by:
Hi all, I have a confusing question on ASP.NET cookies usage: 1> Response.Cookies("test").value = Now 2> Response.Write(Request.Cookies("test").value) 3> 4> Response.write("<hr>") 5>...
6
by: Stephane | last post by:
Hi, I have a login page where if the user wants his access codes to be saved are set into a cookie. In the logout page, I want to delete those cookies. I tried this and this is not working at...
3
by: user | last post by:
Hi everyone, May I know the standard way of reading in cookies in ASP.net using VB.net? In classic asp, i can do this: If request.cookies("user") = "abc" then blah blah
0
by: rn5a | last post by:
This is how I am creating & then reading cookies: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) 'create cookies Response.Cookies("UserName").Value = "Ron"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.