Connecting Tech Pros Worldwide Forums | Help | Site Map

Session Variable naming conventions.

Control Freq
Guest
 
Posts: n/a
#1: Mar 10 '07
Hi,
Not sure if this is the right NG for this, but, is there a convention
for the variable names of a Session variable?

I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
guidance appreciated.

Regards


=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
 
Posts: n/a
#2: Mar 10 '07

re: Session Variable naming conventions.


You can call your Session variable "Hamburger", if that "floats your boat".
What's important is that they make sense to the next developer who comes
along after you get a better job and leave...
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




"Control Freq" wrote:
Quote:
Hi,
Not sure if this is the right NG for this, but, is there a convention
for the variable names of a Session variable?
>
I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
guidance appreciated.
>
Regards
>
>
James Irvine
Guest
 
Posts: n/a
#3: Mar 11 '07

re: Session Variable naming conventions.


Control Freq wrote:
Quote:
Hi,
Not sure if this is the right NG for this, but, is there a convention
for the variable names of a Session variable?
>
I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
guidance appreciated.
>
Regards

Isn't there some formalized naming convention spec along these lines?
It has a name, which escapes me, but goes something like:

no spaces, use one string, starting with a lowercase character, then use
caps for each new word, i.e:

currentReportingQuarter

tblEmployees

rptMonthlySales


something like that...

mark carew
Guest
 
Posts: n/a
#4: Mar 11 '07

re: Session Variable naming conventions.


Hi
The name is camel but it is not mandated for session variables. I use all
uppercase.
Mark
Quote:
>
>
Isn't there some formalized naming convention spec along these lines?
It has a name, which escapes me, but goes something like:
>
no spaces, use one string, starting with a lowercase character, then use
caps for each new word, i.e:
>
currentReportingQuarter
>
Mark Rae
Guest
 
Posts: n/a
#5: Mar 11 '07

re: Session Variable naming conventions.


"mark carew" <markcarew@magicwanddept.com.auwrote in message
news:4oxkmvbhv8g4$.5x8sc2jiam53$.dlg@40tude.net...
Quote:
The name is camel but it is not mandated for session variables. I use all
uppercase.
Naming conventions aren't *mandated* for anything at all, otherwise they
wouldn't be conventions...


Bjorn Sagbakken
Guest
 
Posts: n/a
#6: Mar 11 '07

re: Session Variable naming conventions.


I thought the name was Hungarian Notation.

Bjorn
Quote:
Hi
The name is camel but it is not mandated for session variables. I use all
uppercase.
Mark
Quote:
>>
>>
>Isn't there some formalized naming convention spec along these lines?
>It has a name, which escapes me, but goes something like:
>>
>no spaces, use one string, starting with a lowercase character, then use
>caps for each new word, i.e:
>>
>currentReportingQuarter
>>

Juan T. Llibre
Guest
 
Posts: n/a
#7: Mar 11 '07

re: Session Variable naming conventions.


Hungarian notation is a special case of pascal notation.

With Hungarian notation, you also include information in the name of the variable,
i.e., whether it is numeric, has a decimal value, or is text...or it is whatever

That helps to identify the type of information being stored.
Hungarian notation is not favored by many programmers.

Another variation is Pascal notation, which capitalizes all words.

pascal notation : LikeThis
camel notation : likeThis
hungarian notation : txtLikeThis, rstLikeThis

Yet another one uses underscores : like_this or like_This or Like_This_and_That



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espańol : http://asp.net.do/foros/
===================================
"Bjorn Sagbakken" <bjo-sag@online.nowrote in message news:fOWdnS152-zgXm7YRVnzvA@telenor.com...
Quote:
>I thought the name was Hungarian Notation.
>
Bjorn
>
Quote:
>Hi
>The name is camel but it is not mandated for session variables. I use all
>uppercase.
>Mark
Quote:
>>>
>>>
>>Isn't there some formalized naming convention spec along these lines?
>>It has a name, which escapes me, but goes something like:
>>>
>>no spaces, use one string, starting with a lowercase character, then use
>>caps for each new word, i.e:
>>>
>>currentReportingQuarter
>>>
>
>

John Saunders
Guest
 
Posts: n/a
#8: Mar 11 '07

re: Session Variable naming conventions.


"Control Freq" <nick@nhthomas.freeserve.co.ukwrote in message
news:1173562084.607783.190750@c51g2000cwc.googlegr oups.com...
Quote:
Hi,
Not sure if this is the right NG for this, but, is there a convention
for the variable names of a Session variable?
>
I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
guidance appreciated.
I'm not sure what you mean whan you say "session variable". Do you mean
something accessed via Session["variable"] (Session("variable") in VB.NET)?

John


=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
 
Posts: n/a
#9: Mar 12 '07

re: Session Variable naming conventions.


John Saunders wrote:
Quote:
"Control Freq" <nick@nhthomas.freeserve.co.ukwrote in message
news:1173562084.607783.190750@c51g2000cwc.googlegr oups.com...
Quote:
>Hi,
>Not sure if this is the right NG for this, but, is there a convention
>for the variable names of a Session variable?
>>
>I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
>guidance appreciated.
>
I'm not sure what you mean whan you say "session variable". Do you mean
something accessed via Session["variable"] (Session("variable") in VB.NET)?
>
John
>
Yes. Entries put in the Session.Item collection is generally referred to
as session variables.

--
Göran Andersson
_____
http://www.guffa.com
John Saunders
Guest
 
Posts: n/a
#10: Mar 12 '07

re: Session Variable naming conventions.


"Göran Andersson" <guffa@guffa.comwrote in message
news:OetX0WDZHHA.4008@TK2MSFTNGP05.phx.gbl...
Quote:
John Saunders wrote:
Quote:
>"Control Freq" <nick@nhthomas.freeserve.co.ukwrote in message
>news:1173562084.607783.190750@c51g2000cwc.googleg roups.com...
Quote:
>>Hi,
>>Not sure if this is the right NG for this, but, is there a convention
>>for the variable names of a Session variable?
>>>
>>I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
>>guidance appreciated.
>>
>I'm not sure what you mean whan you say "session variable". Do you mean
>something accessed via Session["variable"] (Session("variable") in
>VB.NET)?
>>
>John
>>
>
Yes. Entries put in the Session.Item collection is generally referred to
as session variables.
Thanks, I was aware of that. I was asking the OP.

John


=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
 
Posts: n/a
#11: Mar 12 '07

re: Session Variable naming conventions.


John Saunders wrote:
Quote:
"Göran Andersson" <guffa@guffa.comwrote in message
news:OetX0WDZHHA.4008@TK2MSFTNGP05.phx.gbl...
Quote:
>John Saunders wrote:
Quote:
>>"Control Freq" <nick@nhthomas.freeserve.co.ukwrote in message
>>news:1173562084.607783.190750@c51g2000cwc.google groups.com...
>>>Hi,
>>>Not sure if this is the right NG for this, but, is there a convention
>>>for the variable names of a Session variable?
>>>>
>>>I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
>>>guidance appreciated.
>>I'm not sure what you mean whan you say "session variable". Do you mean
>>something accessed via Session["variable"] (Session("variable") in
>>VB.NET)?
>>>
>>John
>>>
>Yes. Entries put in the Session.Item collection is generally referred to
>as session variables.
>
Thanks, I was aware of that. I was asking the OP.
>
John
>
Ok. I got the impression from your question that you were unfamiliar
with the term, as you put quotation marks around it.

--
Göran Andersson
_____
http://www.guffa.com
Control Freq
Guest
 
Posts: n/a
#12: Mar 12 '07

re: Session Variable naming conventions.


On 12 Mar, 02:44, "John Saunders" <john.saunders at trizetto.com>
wrote:
Quote:
"Göran Andersson" <g...@guffa.comwrote in message
>
news:OetX0WDZHHA.4008@TK2MSFTNGP05.phx.gbl...
>
>
>
>
>
Quote:
John Saunders wrote:
Quote:
"Control Freq" <n...@nhthomas.freeserve.co.ukwrote in message
>news:1173562084.607783.190750@c51g2000cwc.googleg roups.com...
>Hi,
>Not sure if this is the right NG for this, but, is there a convention
>for the variable names of a Session variable?
>
Quote:
Quote:
>I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
>guidance appreciated.
>
Quote:
Quote:
I'm not sure what you mean whan you say "session variable". Do you mean
something accessed via Session["variable"] (Session("variable") in
VB.NET)?
>
Quote:
Quote:
John
>
Quote:
Yes. Entries put in the Session.Item collection is generally referred to
as session variables.
>
Thanks, I was aware of that. I was asking the OP.
Hi,
Thanks to everyone who took the time to respond to my OP.
Yes, I was referring to Session["SomeName"] = "XYZ".
I wasn't specifically meaning the style of writing the Session
Variable name, i.e using camel casing or pascal casing.
I was really wanting to know if the variable name had the Application
name, and page name embedded in it. I understand that large web apps
might use a lot of session variables, so is it a good idea to separate
them using something like "OrderEntry_DespatchDate", or
"CustomerEntry_ContactName", using the first words to specify which
screen the variable is used?

Otr, is there a better way of doing this sort of thing?

Thanks

Quote:
>
John- Hide quoted text -
>
- Show quoted text -

JDC
Guest
 
Posts: n/a
#13: Mar 12 '07

re: Session Variable naming conventions.


On Mar 12, 2:42 pm, "Control Freq" <n...@nhthomas.freeserve.co.uk>
wrote:
Quote:
Yes, I was referring to Session["SomeName"] = "XYZ".
I wasn't specifically meaning the style of writing the Session
Variable name, i.e using camel casing or pascal casing.
I was really wanting to know if the variable name had the Application
name, and page name embedded in it. I understand that large web apps
might use a lot of session variables, so is it a good idea to separate
them using something like "OrderEntry_DespatchDate", or
"CustomerEntry_ContactName", using the first words to specify which
screen the variable is used?
>
Otr, is there a better way of doing this sort of thing?
I think that putting the page name as part of the variable name could
cause maintenance problems in the future (or at the very least code
smells). And what happens when a variable is referenced across pages
(which is part of reason for using them)?

I suppose you could use your full namespace:
Session["MyCompany.MyApp.XYZ"], but again once you start putting stuff
like this in strings you're asking for maintenance troubles.

Here's what I tend to do:
- use the same naming convention as for classes (i.e. pascal
notation), and just use a sensible, meaningful name (just pretend
you're naming a function and you won't go far wrong).
- use a base class for my pages, and wrap session variables into a
strongly-typed property in the base class. I can provide an example if
you like.

HTH

JC

Mark Rae
Guest
 
Posts: n/a
#14: Mar 12 '07

re: Session Variable naming conventions.


"JDC" <jeremy.d.collins@gmail.comwrote in message
news:1173714168.422819.155180@q40g2000cwq.googlegr oups.com...
Quote:
smells). And what happens when a variable is referenced across pages
(which is part of reason for using them)?
Yes, I was wondering that... :-)


Mike Hofer
Guest
 
Posts: n/a
#15: Mar 12 '07

re: Session Variable naming conventions.


On Mar 12, 11:42 am, "JDC" <jeremy.d.coll...@gmail.comwrote:
Quote:
On Mar 12, 2:42 pm, "Control Freq" <n...@nhthomas.freeserve.co.uk>
wrote:
>
Quote:
Yes, I was referring to Session["SomeName"] = "XYZ".
I wasn't specifically meaning the style of writing the Session
Variable name, i.e using camel casing or pascal casing.
I was really wanting to know if the variable name had the Application
name, and page name embedded in it. I understand that large web apps
might use a lot of session variables, so is it a good idea to separate
them using something like "OrderEntry_DespatchDate", or
"CustomerEntry_ContactName", using the first words to specify which
screen the variable is used?
>
Quote:
Otr, is there a better way of doing this sort of thing?
>
I think that putting the page name as part of the variable name could
cause maintenance problems in the future (or at the very least code
smells). And what happens when a variable is referenced across pages
(which is part of reason for using them)?
>
I suppose you could use your full namespace:
Session["MyCompany.MyApp.XYZ"], but again once you start putting stuff
like this in strings you're asking for maintenance troubles.
>
Here's what I tend to do:
- use the same naming convention as for classes (i.e. pascal
notation), and just use a sensible, meaningful name (just pretend
you're naming a function and you won't go far wrong).
- use a base class for my pages, and wrap session variables into a
strongly-typed property in the base class. I can provide an example if
you like.
>
HTH
>
JC
Call me lazy, but I wrote a session wrapper class that encapsulated
all the session variables in properties. Like so:

Imports System.Web.SessionState

Friend NotInheritable Class MySession

Private Const CompanySessionKey As String = "Company"

Private Shared ReadOnly Property Session As HttpSessionState
Get
Return HttpContext.Current.Session
End Get
End Property

Public Shared Property Company As String
Get
Return DirectCast(Session(CompanySessionKey), String)
End Get
Set(ByVal value As String)
Session(CompanySessionKey) = value
End Set
End Property

End Class

That way, I don't have to think about the session variable names
anywhere else in the code. No chance of typos. And the constants are
defined in one place, close to the properties that use them.

The calling code consequently looks like this:

lblCompanyName.Text = MySession.Company

Code it once, and forget about it. It's a lesson I learned from the
configuration settings stuff in ASP.NET 2.0, and it was well worth the
learning.

Hope this helps!
Mike

BillE
Guest
 
Posts: n/a
#16: Mar 13 '07

re: Session Variable naming conventions.


In IE7, if the same web app is opened on multiple tabs the session variables
are shared between the tabs - changing the value of a variable in one tab
changes it for all tabs. This is also true if the user opens a new browser
instance with Ctrl-N key sequence.

So if I have Customer A open on tab 1, and Customer B open on tab 2, how do
you store the Customer ID in a session variable without it being changed by
activity on another tab?

Bill


"Mike Hofer" <kchighland@gmail.comwrote in message
news:1173728045.900099.191490@q40g2000cwq.googlegr oups.com...
Quote:
On Mar 12, 11:42 am, "JDC" <jeremy.d.coll...@gmail.comwrote:
Quote:
>On Mar 12, 2:42 pm, "Control Freq" <n...@nhthomas.freeserve.co.uk>
>wrote:
>>
Quote:
Yes, I was referring to Session["SomeName"] = "XYZ".
I wasn't specifically meaning the style of writing the Session
Variable name, i.e using camel casing or pascal casing.
I was really wanting to know if the variable name had the Application
name, and page name embedded in it. I understand that large web apps
might use a lot of session variables, so is it a good idea to separate
them using something like "OrderEntry_DespatchDate", or
"CustomerEntry_ContactName", using the first words to specify which
screen the variable is used?
>>
Quote:
Otr, is there a better way of doing this sort of thing?
>>
>I think that putting the page name as part of the variable name could
>cause maintenance problems in the future (or at the very least code
>smells). And what happens when a variable is referenced across pages
>(which is part of reason for using them)?
>>
>I suppose you could use your full namespace:
>Session["MyCompany.MyApp.XYZ"], but again once you start putting stuff
>like this in strings you're asking for maintenance troubles.
>>
>Here's what I tend to do:
>- use the same naming convention as for classes (i.e. pascal
>notation), and just use a sensible, meaningful name (just pretend
>you're naming a function and you won't go far wrong).
>- use a base class for my pages, and wrap session variables into a
>strongly-typed property in the base class. I can provide an example if
>you like.
>>
>HTH
>>
>JC
>
Call me lazy, but I wrote a session wrapper class that encapsulated
all the session variables in properties. Like so:
>
Imports System.Web.SessionState
>
Friend NotInheritable Class MySession
>
Private Const CompanySessionKey As String = "Company"
>
Private Shared ReadOnly Property Session As HttpSessionState
Get
Return HttpContext.Current.Session
End Get
End Property
>
Public Shared Property Company As String
Get
Return DirectCast(Session(CompanySessionKey), String)
End Get
Set(ByVal value As String)
Session(CompanySessionKey) = value
End Set
End Property
>
End Class
>
That way, I don't have to think about the session variable names
anywhere else in the code. No chance of typos. And the constants are
defined in one place, close to the properties that use them.
>
The calling code consequently looks like this:
>
lblCompanyName.Text = MySession.Company
>
Code it once, and forget about it. It's a lesson I learned from the
configuration settings stuff in ASP.NET 2.0, and it was well worth the
learning.
>
Hope this helps!
Mike
>

=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
 
Posts: n/a
#17: Mar 13 '07

re: Session Variable naming conventions.


If you have two windows or tabs in the same session, they will be using
the same session variables. There is nothing that you can do to change that.

BillE wrote:
Quote:
In IE7, if the same web app is opened on multiple tabs the session variables
are shared between the tabs - changing the value of a variable in one tab
changes it for all tabs. This is also true if the user opens a new browser
instance with Ctrl-N key sequence.
>
So if I have Customer A open on tab 1, and Customer B open on tab 2, how do
you store the Customer ID in a session variable without it being changed by
activity on another tab?
>
Bill
>
>
"Mike Hofer" <kchighland@gmail.comwrote in message
news:1173728045.900099.191490@q40g2000cwq.googlegr oups.com...
Quote:
>On Mar 12, 11:42 am, "JDC" <jeremy.d.coll...@gmail.comwrote:
Quote:
>>On Mar 12, 2:42 pm, "Control Freq" <n...@nhthomas.freeserve.co.uk>
>>wrote:
>>>
>>>Yes, I was referring to Session["SomeName"] = "XYZ".
>>>I wasn't specifically meaning the style of writing the Session
>>>Variable name, i.e using camel casing or pascal casing.
>>>I was really wanting to know if the variable name had the Application
>>>name, and page name embedded in it. I understand that large web apps
>>>might use a lot of session variables, so is it a good idea to separate
>>>them using something like "OrderEntry_DespatchDate", or
>>>"CustomerEntry_ContactName", using the first words to specify which
>>>screen the variable is used?
>>>Otr, is there a better way of doing this sort of thing?
>>I think that putting the page name as part of the variable name could
>>cause maintenance problems in the future (or at the very least code
>>smells). And what happens when a variable is referenced across pages
>>(which is part of reason for using them)?
>>>
>>I suppose you could use your full namespace:
>>Session["MyCompany.MyApp.XYZ"], but again once you start putting stuff
>>like this in strings you're asking for maintenance troubles.
>>>
>>Here's what I tend to do:
>>- use the same naming convention as for classes (i.e. pascal
>>notation), and just use a sensible, meaningful name (just pretend
>>you're naming a function and you won't go far wrong).
>>- use a base class for my pages, and wrap session variables into a
>>strongly-typed property in the base class. I can provide an example if
>>you like.
>>>
>>HTH
>>>
>>JC
>Call me lazy, but I wrote a session wrapper class that encapsulated
>all the session variables in properties. Like so:
>>
>Imports System.Web.SessionState
>>
>Friend NotInheritable Class MySession
>>
> Private Const CompanySessionKey As String = "Company"
>>
> Private Shared ReadOnly Property Session As HttpSessionState
> Get
> Return HttpContext.Current.Session
> End Get
> End Property
>>
> Public Shared Property Company As String
> Get
> Return DirectCast(Session(CompanySessionKey), String)
> End Get
> Set(ByVal value As String)
> Session(CompanySessionKey) = value
> End Set
> End Property
>>
>End Class
>>
>That way, I don't have to think about the session variable names
>anywhere else in the code. No chance of typos. And the constants are
>defined in one place, close to the properties that use them.
>>
>The calling code consequently looks like this:
>>
> lblCompanyName.Text = MySession.Company
>>
>Code it once, and forget about it. It's a lesson I learned from the
>configuration settings stuff in ASP.NET 2.0, and it was well worth the
>learning.
>>
>Hope this helps!
>Mike
>>
>
>

--
Göran Andersson
_____
http://www.guffa.com
John Saunders
Guest
 
Posts: n/a
#18: Mar 13 '07

re: Session Variable naming conventions.



"BillE" <belgie@datamti.comwrote in message
news:%239gj8oaZHHA.4420@TK2MSFTNGP02.phx.gbl...
Quote:
In IE7, if the same web app is opened on multiple tabs the session
variables are shared between the tabs - changing the value of a variable
in one tab changes it for all tabs. This is also true if the user opens a
new browser instance with Ctrl-N key sequence.
>
So if I have Customer A open on tab 1, and Customer B open on tab 2, how
do you store the Customer ID in a session variable without it being
changed by activity on another tab?
You don't store the customer id in a session variable.

Why do you want is stored in a Session variable?

John


Closed Thread