473,396 Members | 1,809 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,396 software developers and data experts.

ASP.Net 2.0 Static members

I want to have a global variable in my app so I can change my DB connect
string for all the pages based on the person's login information. I have a
class that has a static string. I can get/set that from any page and it
works good. ***Is it OK to use statics in this manner or is there a chance
that a different user will affect the static members that yet another user
is using (the whole life cycle for internet apps thing).

I have it running and it works fine but I wonder...

I have seen lots of posts on this but many conflict so I am asking here for
clarification.

Thanks you!


Mar 27 '06 #1
6 1138
No, this is not correct.

Static members are shared between user sessions. Every new user will
overwrite them.

You should use session variables.

Eliyahu

"devg" <de****@noemail.noemail> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
I want to have a global variable in my app so I can change my DB connect
string for all the pages based on the person's login information. I have a
class that has a static string. I can get/set that from any page and it
works good. ***Is it OK to use statics in this manner or is there a chance
that a different user will affect the static members that yet another user
is using (the whole life cycle for internet apps thing).

I have it running and it works fine but I wonder...

I have seen lots of posts on this but many conflict so I am asking here
for clarification.

Thanks you!

Mar 27 '06 #2
Since I just need to store a simple string to be available to all pages I
would love to use Session Variables but I have been hesitent since I have
seen many posts saying this is not good practice. I am using ASP.NET 2.0 so
I wonder if using Session Vars in this way is OK now (compared to classic
ASP which I assume it was not good)?
Thank you!

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:eo**************@TK2MSFTNGP14.phx.gbl...
No, this is not correct.

Static members are shared between user sessions. Every new user will
overwrite them.

You should use session variables.

Eliyahu

"devg" <de****@noemail.noemail> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
I want to have a global variable in my app so I can change my DB connect
string for all the pages based on the person's login information. I have a
class that has a static string. I can get/set that from any page and it
works good. ***Is it OK to use statics in this manner or is there a chance
that a different user will affect the static members that yet another user
is using (the whole life cycle for internet apps thing).

I have it running and it works fine but I wonder...

I have seen lots of posts on this but many conflict so I am asking here
for clarification.

Thanks you!


Mar 27 '06 #3
I can't think of anything bad in using session variables for your purpose.

Eliyahu

"devg" <de****@noemail.noemail> wrote in message
news:eB**************@TK2MSFTNGP10.phx.gbl...
Since I just need to store a simple string to be available to all pages I
would love to use Session Variables but I have been hesitent since I have
seen many posts saying this is not good practice. I am using ASP.NET 2.0
so I wonder if using Session Vars in this way is OK now (compared to
classic ASP which I assume it was not good)?
Thank you!

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:eo**************@TK2MSFTNGP14.phx.gbl...
No, this is not correct.

Static members are shared between user sessions. Every new user will
overwrite them.

You should use session variables.

Eliyahu

"devg" <de****@noemail.noemail> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
I want to have a global variable in my app so I can change my DB connect
string for all the pages based on the person's login information. I have
a class that has a static string. I can get/set that from any page and it
works good. ***Is it OK to use statics in this manner or is there a
chance that a different user will affect the static members that yet
another user is using (the whole life cycle for internet apps thing).

I have it running and it works fine but I wonder...

I have seen lots of posts on this but many conflict so I am asking here
for clarification.

Thanks you!



Mar 27 '06 #4
Hi Devg,

I agree with Eliyahu that for your scenario, use SessionState variable is
the preferred approach. Static class member can only store data which will
be shared among the whle application(Appdomain). And for sessionState, if
you don't store two much data in it, that should be ok.

Please feel free to post here if you have any other consideration or
concerns.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

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

Mar 28 '06 #5
Thank you Eliyahu and Steven for your info!
I see clearly that static is not the way to go now.
I am concerened that I have seen so many negative articles on using Session
(and I am so used to not using them from classic ASP!) that I wonder if
there is a better way? I suppose Session would be ok for just a string or
two but I am also wondering if perhaps putting the data in the
authentication ticket would be good too (so I would have a role for each
user that would point to what DB they were to use).
Thanks for all your ideas and info -- what do you think about using UserData
in the ticket vs. Session?

"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:5c**************@TK2MSFTNGXA01.phx.gbl...
Hi Devg,

I agree with Eliyahu that for your scenario, use SessionState variable is
the preferred approach. Static class member can only store data which will
be shared among the whle application(Appdomain). And for sessionState, if
you don't store two much data in it, that should be ok.

Please feel free to post here if you have any other consideration or
concerns.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

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

Mar 28 '06 #6
Thank you for the response Devg,

Authentication cookie(ticket) is also ok, and the difference between
sessionstate is that authentication ticket store in client-side cookie, so
if we store to much data , it'll increase the data tranferred between
client server(though we won't store much data in it generally ;)). BTW, I
just forget the mention the user profile in ASP.NET 2.0, have you ever
considered to use this as the storage?

#ASP.NET Profile Properties Overview
http://msdn2.microsoft.com/en-us/lib...xs(VS.80).aspx

#Storing User Profiles
http://www.asp.net/QuickStart/aspnet...e/default.aspx

Profile service is used to help store user specific data and the default
storage is the database(sqlserver).

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

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


Mar 29 '06 #7

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

Similar topics

3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
15
by: Samee Zahur | last post by:
Question: How do friend functions and static member functions differ in terms of functionality? I mean, neither necessarily needs an object of the class to be created before they are called and...
6
by: lovecreatesbeauty | last post by:
Hello Experts, Why static data members can be declared as the type of class which it belongs to? Inside a class, non-static data members such as pointers and references can be declared as...
13
by: Adam H. Peterson | last post by:
I just made an observation and I wondered if it's generally known (or if I'm missing something). My observation is that static protected members are essentially useless, only a hint to the user. ...
3
by: Mauzi | last post by:
hi, this may sound odd and noob like, but what is the 'big' difference between static and non-static funcitons ? is there any performace differnce? what is the best way to use them ? thnx ...
6
by: Matt | last post by:
All of a sudden all my C# apps require the keyword static on all global fields and methods that I create. Even in the simplest of console apps. Can someone tell me what I have inadvertenly set in...
11
by: dee | last post by:
OleDbCommand class like many .NET classes has the following description in its help file: "Thread Safety Any public static (Shared in Visual Basic) members of this type are safe for...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
8
by: crjjrc | last post by:
Hi, I've got a base class and some derived classes that look something like this: class Base { public: int getType() { return type; } private: static const int type = 0; };
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
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,...
0
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...
0
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,...
0
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...
0
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...

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.