hey all,
can someone please tell me if there's a big difference among the following:
i want to store a string and an int in session.
is it better to store it like:
1. delimited string (i.e. session["test"]="test1" + ";" + 1
2. in an array
3. or 2 separate sessions
how would each one rate?
thanks,
rodcharIf they are not related, then I would store them in seperate session
variables.
If they're related...lets say you want to store the
EmpID (int) and EmployeeLoginName (string), I would create a mini wrapper
object.
[Serializable]
public class EmployeeLoginInfo
{
private int _empID = 0;
private string _employeeLoginName = string.Empty;
public EmployeeLoginInfo( int empID , string employeeLoginName )
{
_empID = empID;
_employeeLoginName = employeeLoginName;
}
public int EmpID { { return _empID;}}
public string EmployeeLoginName { get { return _employeeLoginName;}}
}
and then I would session that mini object.
Delimited String << Heck No
Array << Heck No
That's my vote.
To me, using the mini object means I only have to pay the casting price
once.
And my code make more sense, because I don't have a bunch of disjoint
properties flying all over the place.
You can check this blog entry as well:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!151.entry
"rodchar" <rodchar@.discussions.microsoft.com> wrote in message
news:74A6AE05-25B3-4CF5-8150-3E312CDFE6AB@.microsoft.com...
> hey all,
> can someone please tell me if there's a big difference among the
> following:
> i want to store a string and an int in session.
> is it better to store it like:
> 1. delimited string (i.e. session["test"]="test1" + ";" + 1
> 2. in an array
> 3. or 2 separate sessions
> how would each one rate?
> thanks,
> rodchar
>
"sloan" <sloan@.ipass.net> wrote in message
news:OOIA6HQgIHA.4164@.TK2MSFTNGP05.phx.gbl...
> [Serializable]
Not necessary if the class to be stored in Session contains only primitive
datatypes:
http://safari.oreilly.com/059600117...p-CHP-21-SECT-6
> Delimited String << Heck No
Agreed.
> Array << Heck No
Probably not, though generics are usually OK to store in Session...
Mark Rae
ASP.NET MVP
http://www.markrae.net
should the mini object be nested in a class or would it be better in a
separate file?
"sloan" wrote:
> If they are not related, then I would store them in seperate session
> variables.
> If they're related...lets say you want to store the
> EmpID (int) and EmployeeLoginName (string), I would create a mini wrapper
> object.
> [Serializable]
> public class EmployeeLoginInfo
> {
> private int _empID = 0;
> private string _employeeLoginName = string.Empty;
> public EmployeeLoginInfo( int empID , string employeeLoginName )
> {
> _empID = empID;
> _employeeLoginName = employeeLoginName;
> }
> public int EmpID { { return _empID;}}
> public string EmployeeLoginName { get { return _employeeLoginName;}}
> }
>
> and then I would session that mini object.
>
> Delimited String << Heck No
> Array << Heck No
>
> That's my vote.
>
> To me, using the mini object means I only have to pay the casting price
> once.
> And my code make more sense, because I don't have a bunch of disjoint
> properties flying all over the place.
> You can check this blog entry as well:
> http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!151.entry
>
> "rodchar" <rodchar@.discussions.microsoft.com> wrote in message
> news:74A6AE05-25B3-4CF5-8150-3E312CDFE6AB@.microsoft.com...
>
>
"rodchar" <rodchar@.discussions.microsoft.com> wrote in message
news:322B0134-B070-4C18-A041-F2718BB1E4B7@.microsoft.com...
> should the mini object be nested in a class
The (mini) object *is* a class...
> or would it be better in a separate file?
Totally irrelevant to the compiler...
Mark Rae
ASP.NET MVP
http://www.markrae.net
thanks for the help everyone,
rod.
"rodchar" wrote:
> hey all,
> can someone please tell me if there's a big difference among the following
:
> i want to store a string and an int in session.
> is it better to store it like:
> 1. delimited string (i.e. session["test"]="test1" + ";" + 1
> 2. in an array
> 3. or 2 separate sessions
> how would each one rate?
> thanks,
> rodchar
>
Showing posts with label among. Show all posts
Showing posts with label among. Show all posts
Wednesday, March 28, 2012
Thursday, March 22, 2012
structure
what is the best way of sharing a structure among different pages of my
asp.net application?Hi,
asp.net application?Hi,
Try putting the Structure in a separate file to your web pages and making it
'public static' (or 'Public Shared' in VB.NET).
James
"Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
news:%23LYbPYrUEHA.4048@.TK2MSFTNGP12.phx.gbl...
> what is the best way of sharing a structure among different pages of my
> asp.net application?
structure
what is the best way of sharing a structure among different pages of my
asp.net application?Muhammad,
I assume you mean the Visual style of the pages?
There are a few ways this can be done, I personally use
WilsonMasterPages: -
http://authors.aspalliance.com/Paul...Articles/?id=14
Hth,
Phil Winstanley
Microsoft ASP.NET MVP
http://www.myservicescentral.com
Hi,
Try putting the Structure in a separate file to your web pages and making it
'public static' (or 'Public Shared' in VB.NET).
James
"Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
news:%23LYbPYrUEHA.4048@.TK2MSFTNGP12.phx.gbl...
> what is the best way of sharing a structure among different pages of my
> asp.net application?
>
sorry didn't make myself clear, I want to use a data structure and assign
values to its members on different pages and offcourse want to retain all
values assigned on different pages.
"Phil Winstanley [Microsoft MVP ASP.NET]" <phil@.winstanley.name> wrote i
n
message news:camdst$oni@.odak26.prod.google.com...
> Muhammad,
> I assume you mean the Visual style of the pages?
> There are a few ways this can be done, I personally use
> WilsonMasterPages: -
> http://authors.aspalliance.com/Paul...Articles/?id=14
> Hth,
> Phil Winstanley
> Microsoft ASP.NET MVP
> http://www.myservicescentral.com
>
Muhammad,
You could store this structure in the Application object, and update it
there. Although you may have threading issues, so use locking when
accessing it.
James
"Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
news:eFIQYgrUEHA.2388@.TK2MSFTNGP09.phx.gbl...
> sorry didn't make myself clear, I want to use a data structure and assign
> values to its members on different pages and offcourse want to retain all
> values assigned on different pages.
> "Phil Winstanley [Microsoft MVP ASP.NET]" <phil@.winstanley.name> wrote
in
> message news:camdst$oni@.odak26.prod.google.com...
>
Is it possible to definte a user defined stucture as application variable.
just of the sake of example
public struct student
{
int id;
string name;
float age;
string address1;
string address2;
}
How can I create an object of student type as an application variable?
"James Doran" <jamied1@.NO_SPAMbreathe.com> wrote in message
news:e4qMukrUEHA.2520@.TK2MSFTNGP10.phx.gbl...
> Muhammad,
> You could store this structure in the Application object, and update it
> there. Although you may have threading issues, so use locking when
> accessing it.
> James
> "Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
> news:eFIQYgrUEHA.2388@.TK2MSFTNGP09.phx.gbl...
assign
all
in
>
Define the struct as you have in a file within your project. In the
Application_Start event handler in the Global.asax file of your project,
enter the following code:
VB:
Dim oStudent As SomeNamespace.student
' Initialise
oStudent.ID = 0
oStudent.Age = 15
..
' Add the student to the application object
Application("Student") = oStudent
C#:
SomeNamespace.student oStudent;
// Initialise
oStudent.ID = 0;
oStudent.Age = 15;
..
// Add the student to the application object
Application["Student"] = oStudent;
The student struct will then be available to each page. To access it, use
the following code:
VB:
CType(Application("Student"), SomeNamespace.student) ...
C#:
(SomeNamespace.student)Application["Student"] ...
Hope this helps,
James
"Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
news:uTCmXtrUEHA.2972@.TK2MSFTNGP12.phx.gbl...
> Is it possible to definte a user defined stucture as application variable.
> just of the sake of example
> public struct student
> {
> int id;
> string name;
> float age;
> string address1;
> string address2;
> }
> How can I create an object of student type as an application variable?
> "James Doran" <jamied1@.NO_SPAMbreathe.com> wrote in message
> news:e4qMukrUEHA.2520@.TK2MSFTNGP10.phx.gbl...
> assign
> all
> in
>
Excellent! that make 100% sense, will give it a go now thank you for help.
"James Doran" <jamied1@.NO_SPAMbreathe.com> wrote in message
news:u2jIuzrUEHA.1036@.TK2MSFTNGP12.phx.gbl...
> Define the struct as you have in a file within your project. In the
> Application_Start event handler in the Global.asax file of your project,
> enter the following code:
> VB:
> Dim oStudent As SomeNamespace.student
> ' Initialise
> oStudent.ID = 0
> oStudent.Age = 15
> ...
> ' Add the student to the application object
> Application("Student") = oStudent
> C#:
> SomeNamespace.student oStudent;
> // Initialise
> oStudent.ID = 0;
> oStudent.Age = 15;
> ...
> // Add the student to the application object
> Application["Student"] = oStudent;
> The student struct will then be available to each page. To access it, use
> the following code:
> VB:
> CType(Application("Student"), SomeNamespace.student) ...
> C#:
> (SomeNamespace.student)Application["Student"] ...
> Hope this helps,
> James
> "Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
> news:uTCmXtrUEHA.2972@.TK2MSFTNGP12.phx.gbl...
variable.
it
retain
wrote
>
Muhammad,
James' sample is great, you might also want to take a look at an
article I put together a while ago on the subject: -
http://aspalliance.com/431
Hth,
Phil Winstanley
Microsoft ASP.NET MVP
http://www.myservicescentral.com
that is extremely helpful. thank you phil.
"Phil Winstanley [Microsoft MVP ASP.NET]" <phil@.winstanley.name> wrote i
n
message news:camn5j$65l@.odak26.prod.google.com...
> Muhammad,
> James' sample is great, you might also want to take a look at an
> article I put together a while ago on the subject: -
> http://aspalliance.com/431
> Hth,
> Phil Winstanley
> Microsoft ASP.NET MVP
> http://www.myservicescentral.com
>
asp.net application?Muhammad,
I assume you mean the Visual style of the pages?
There are a few ways this can be done, I personally use
WilsonMasterPages: -
http://authors.aspalliance.com/Paul...Articles/?id=14
Hth,
Phil Winstanley
Microsoft ASP.NET MVP
http://www.myservicescentral.com
Hi,
Try putting the Structure in a separate file to your web pages and making it
'public static' (or 'Public Shared' in VB.NET).
James
"Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
news:%23LYbPYrUEHA.4048@.TK2MSFTNGP12.phx.gbl...
> what is the best way of sharing a structure among different pages of my
> asp.net application?
>
sorry didn't make myself clear, I want to use a data structure and assign
values to its members on different pages and offcourse want to retain all
values assigned on different pages.
"Phil Winstanley [Microsoft MVP ASP.NET]" <phil@.winstanley.name> wrote i
n
message news:camdst$oni@.odak26.prod.google.com...
> Muhammad,
> I assume you mean the Visual style of the pages?
> There are a few ways this can be done, I personally use
> WilsonMasterPages: -
> http://authors.aspalliance.com/Paul...Articles/?id=14
> Hth,
> Phil Winstanley
> Microsoft ASP.NET MVP
> http://www.myservicescentral.com
>
Muhammad,
You could store this structure in the Application object, and update it
there. Although you may have threading issues, so use locking when
accessing it.
James
"Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
news:eFIQYgrUEHA.2388@.TK2MSFTNGP09.phx.gbl...
> sorry didn't make myself clear, I want to use a data structure and assign
> values to its members on different pages and offcourse want to retain all
> values assigned on different pages.
> "Phil Winstanley [Microsoft MVP ASP.NET]" <phil@.winstanley.name> wrote
in
> message news:camdst$oni@.odak26.prod.google.com...
>
Is it possible to definte a user defined stucture as application variable.
just of the sake of example
public struct student
{
int id;
string name;
float age;
string address1;
string address2;
}
How can I create an object of student type as an application variable?
"James Doran" <jamied1@.NO_SPAMbreathe.com> wrote in message
news:e4qMukrUEHA.2520@.TK2MSFTNGP10.phx.gbl...
> Muhammad,
> You could store this structure in the Application object, and update it
> there. Although you may have threading issues, so use locking when
> accessing it.
> James
> "Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
> news:eFIQYgrUEHA.2388@.TK2MSFTNGP09.phx.gbl...
assign
all
in
>
Define the struct as you have in a file within your project. In the
Application_Start event handler in the Global.asax file of your project,
enter the following code:
VB:
Dim oStudent As SomeNamespace.student
' Initialise
oStudent.ID = 0
oStudent.Age = 15
..
' Add the student to the application object
Application("Student") = oStudent
C#:
SomeNamespace.student oStudent;
// Initialise
oStudent.ID = 0;
oStudent.Age = 15;
..
// Add the student to the application object
Application["Student"] = oStudent;
The student struct will then be available to each page. To access it, use
the following code:
VB:
CType(Application("Student"), SomeNamespace.student) ...
C#:
(SomeNamespace.student)Application["Student"] ...
Hope this helps,
James
"Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
news:uTCmXtrUEHA.2972@.TK2MSFTNGP12.phx.gbl...
> Is it possible to definte a user defined stucture as application variable.
> just of the sake of example
> public struct student
> {
> int id;
> string name;
> float age;
> string address1;
> string address2;
> }
> How can I create an object of student type as an application variable?
> "James Doran" <jamied1@.NO_SPAMbreathe.com> wrote in message
> news:e4qMukrUEHA.2520@.TK2MSFTNGP10.phx.gbl...
> assign
> all
> in
>
Excellent! that make 100% sense, will give it a go now thank you for help.
"James Doran" <jamied1@.NO_SPAMbreathe.com> wrote in message
news:u2jIuzrUEHA.1036@.TK2MSFTNGP12.phx.gbl...
> Define the struct as you have in a file within your project. In the
> Application_Start event handler in the Global.asax file of your project,
> enter the following code:
> VB:
> Dim oStudent As SomeNamespace.student
> ' Initialise
> oStudent.ID = 0
> oStudent.Age = 15
> ...
> ' Add the student to the application object
> Application("Student") = oStudent
> C#:
> SomeNamespace.student oStudent;
> // Initialise
> oStudent.ID = 0;
> oStudent.Age = 15;
> ...
> // Add the student to the application object
> Application["Student"] = oStudent;
> The student struct will then be available to each page. To access it, use
> the following code:
> VB:
> CType(Application("Student"), SomeNamespace.student) ...
> C#:
> (SomeNamespace.student)Application["Student"] ...
> Hope this helps,
> James
> "Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
> news:uTCmXtrUEHA.2972@.TK2MSFTNGP12.phx.gbl...
variable.
it
retain
wrote
>
Muhammad,
James' sample is great, you might also want to take a look at an
article I put together a while ago on the subject: -
http://aspalliance.com/431
Hth,
Phil Winstanley
Microsoft ASP.NET MVP
http://www.myservicescentral.com
that is extremely helpful. thank you phil.
"Phil Winstanley [Microsoft MVP ASP.NET]" <phil@.winstanley.name> wrote i
n
message news:camn5j$65l@.odak26.prod.google.com...
> Muhammad,
> James' sample is great, you might also want to take a look at an
> article I put together a while ago on the subject: -
> http://aspalliance.com/431
> Hth,
> Phil Winstanley
> Microsoft ASP.NET MVP
> http://www.myservicescentral.com
>
Subscribe to:
Posts (Atom)