473,799 Members | 2,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checking for Session cookies

I was looking at different ways of doing the same thing and at the moment
was looking at the use of "is" and "=", as I have at times found that I will
do something like

if something = 0

and will get an error that says I can't use "=" (or <>) in this case case I
must use "is" ( or not something is). I am trying to find out when this is
the case - when I can use the "=" and when I have to use "is.

For example, I have a small piece of code checking for the existance of a
session cookie:

if session("tom") = nothing then
trace.warn("Tom not there")
trace.warn("Len (session('Tom') ) = " & Len(session("To m")))
if len(session("To m")) = 0 then
trace.warn("als o got a hit on <> 0")
end if
end if
This can also be run as:

if session("tom") is nothing then
trace.warn("Tom not there")
trace.warn("Len (session('Tom') ) = " & Len(session("To m")))
if len(session("To m")) = 0 then
trace.warn("als o got a hit on <> 0")
end if
end if

So 'session("Tom") = nothing' and 'session("Tom") is nothing' as well as
'Len(session("T om"))' are all equivalent.

Not sure if there is a best way or just whatever strikes you fancy.

I do know that in some cases you can't use the "=" and must use "is". I
just don't know why in some cases you can use both (or all 3 ways) and in
some cases you must us "is".

Can someone help me out on the difference?

Thanks,

Tom
Nov 19 '05 #1
2 1177
There are 2 sorts of types if you program in an OO language : reference and
value types

Value types are most built in types like integer, string (I think), money,
etc and you can think of the variable as actualy holding the value.
A reference type is Nothing (null in c#) or contains a reference to the actual
value which is always a class.

If you use a reference type and you want to know whether it contains a value
you do this by asking " is nothing", ie you are asking if it contains a reference.

But VB.NEt isn't so strict and it allows things like

dim i as integer = 5
if i = nothing then ...

This is not stritly right as i is a value type. But VB.NET guessed what you
ment (but guessing is a bad idea for a compiler).

So to be short : if you are dealing with classes you have to use nothing.

To complicate things further structs are value types. I suggest you google
for "difference reference value type" to dig in deeper cause it's quit a
technical topic.

Let me know if you have any more questions..

Cheers,
Tom Pester
I was looking at different ways of doing the same thing and at the
moment was looking at the use of "is" and "=", as I have at times
found that I will do something like

if something = 0

and will get an error that says I can't use "=" (or <>) in this case
case I must use "is" ( or not something is). I am trying to find out
when this is the case - when I can use the "=" and when I have to use
"is.

For example, I have a small piece of code checking for the existance
of a session cookie:

if session("tom") = nothing then
trace.warn("Tom not there")
trace.warn("Len (session('Tom') ) = " & Len(session("To m")))
if len(session("To m")) = 0 then
trace.warn("als o got a hit on <> 0")
end if
end if
This can also be run as:

if session("tom") is nothing then
trace.warn("Tom not there")
trace.warn("Len (session('Tom') ) = " & Len(session("To m")))
if len(session("To m")) = 0 then
trace.warn("als o got a hit on <> 0")
end if
end if
So 'session("Tom") = nothing' and 'session("Tom") is nothing' as well
as 'Len(session("T om"))' are all equivalent.

Not sure if there is a best way or just whatever strikes you fancy.

I do know that in some cases you can't use the "=" and must use "is".
I just don't know why in some cases you can use both (or all 3 ways)
and in some cases you must us "is".

Can someone help me out on the difference?

Thanks,

Tom

Nov 19 '05 #2
I found a good text about it :

http://www.awprofessional.com/conten...gner_item6.pdf

Cheers,
Tom Pester
Nov 19 '05 #3

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

Similar topics

0
14722
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 to get it to work properly. I'm basically trying to connect to this site http://s1.starkingdoms.com/scripts/main.php I am able to get past the authentication login page onto the next screen but I then can't proceed any further because of...
3
3544
by: PM | last post by:
I'm trying to make a kind of search history containing the 3 last searched words. So I'm using 3 Session Variables: Word1 / Word2 / Word3. In order to get this history working, I need to put the last searched word in the following Variable. Ex.: Session("Word3") = Session("Word2") Session("Word2") = Session("Word1")
2
3347
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of the user. I want that cookie should get deleted when user closes the browser without signing out. I think it is done in global.asa file . But i don;t know how to do it?
9
1962
by: RA | last post by:
Hi Please review and let me know if I am correct: 1) My understanding from reading http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/ diforwc-ch05.asp is that asp.net uses cookies to store the user session id, but if cookies are not enabled then it will send the session id as part of the url. Is this correct?
7
2019
by: Marcus | last post by:
I know that when you start a session in PHP, the "cookie" it creates is not the same as those that are stored in your browser's temp folder, and instead is kept in RAM. I am confused because in every session tutorial I have ever read, the author invariably mentions the 2 main ways of propagating sessions - through cookies and appended to the URL. The author also almost always talks about the method being dependent on the user's...
4
4051
by: Jeff | last post by:
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
4
1321
Bob Ross
by: Bob Ross | last post by:
I'm sure I know the answer to this already but.... Does anyone know a good way of checking if cookies are enabled on a browser? I currently have If Request.QueryString("Trying") = "" Then Session.Add("SessionCookie", "ON") Response.Redirect(Request.Path & "?Trying=ON", True) Else If Session("SessionCookie") = "" Then
2
5017
by: StanB | last post by:
I came across this weird problem: 1. Session state stops working after the app is deployed to another server because IE does not accept cookies. 2. It works if cookieless="true" in the web.config 3. Yes, I tried IE - Tools - Privacy - Accept All Cookies and also Override automatic cookie handling, Always allow session cookes
3
5007
by: dihola | last post by:
Hi, I have a website running in IIS7 and it seems to be creating a new session for every request I make. The values I store in Session are lost with every request. This is the forms bit in my web.config: <authentication mode="Forms"> <forms name=".ReMaCRM" loginUrl="~/Login.aspx" defaultUrl="~/Default.aspx" cookieless="AutoDetect" domain="" timeout="10" protection="All" /> </authentication>
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10491
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10247
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10031
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.