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

How Can I Define Global Classes In Web Application ?

How can I define global classes in web application ?

Classes can be set to session variables ?

Thanks
Apr 12 '07 #1
11 2319
Create your class in App_Code folder, you can store any objects in session.

Regards
Prakash.V

"Sylvia A." <sl****@ccc.comwrote in message
news:eI**************@TK2MSFTNGP03.phx.gbl...
How can I define global classes in web application ?

Classes can be set to session variables ?

Thanks


Apr 12 '07 #2
rea:
How can I define global classes in web application ?
1. You can place source code in the App_Code directory.
Any source files you place there will be compiled.

2. You can compile them yourself and place the generated
assembly/assemblies in the /bin directory.

That protects your source code a bit more.

To compile a single source code file, use :

csc /t:library /out:utils.dll utils.cs

To compile all .cs files in a directory to utils.dll ,
use : csc /t:library /out:utils.dll *.cs

If you need to reference a .Net Framework assembly or assemblies,
add them, separated by slashes :

csc /t:library /r:system.dll /r:system.data.dll /out:utils.dll *.cs

If you're using VB.NET instead of C#,
use vbc and source files ending in .vb
instead of using csc and source files ending in .cs.

The syntax is the same for vb and c#.

Once you have compiled your assembly, place it in the /bin
directory of your application, and import the Namespace :

<%@ Import Namespace="YourNamespace" %>

If you're working strictly with VS.NET, compile your assembly
as described and add a reference to it in your VS.NET project.

That will allow you to use Intellisense and get your
assembly's properties, methods, etc. when coding.

re:
Classes can be set to session variables ?
If you mean to use classes to *set* session variables, yes.


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/
===================================
"Sylvia A." <sl****@ccc.comwrote in message news:eI**************@TK2MSFTNGP03.phx.gbl...
How can I define global classes in web application ?
Classes can be set to session variables ?
Thanks

Apr 12 '07 #3
Storing ref types in Session isn't advisable but here you go.

//create it
myObject myObjectInstance = new myObject();

....do work here...

//dump it into session
Session["myObject"] = myObjectInstance;

//pull it back out of session
myObject myObjectInstance = (myObject)Session["myObject"];

I would store the information needed to re-produce the object and it's
state rather than store the object in Session.

On Apr 12, 8:33 am, "Sylvia A." <sly...@ccc.comwrote:
How can I define global classes in web application ?

Classes can be set to session variables ?

Thanks
Apr 12 '07 #4
Storing objects in another object (especially in the session object) is *always* a Bad Idea.

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/
===================================
"carion1" <dd******@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
Storing ref types in Session isn't advisable but here you go.

//create it
myObject myObjectInstance = new myObject();

...do work here...

//dump it into session
Session["myObject"] = myObjectInstance;

//pull it back out of session
myObject myObjectInstance = (myObject)Session["myObject"];

I would store the information needed to re-produce the object and it's
state rather than store the object in Session.

On Apr 12, 8:33 am, "Sylvia A." <sly...@ccc.comwrote:
>How can I define global classes in web application ?

Classes can be set to session variables ?

Thanks

Apr 12 '07 #5
Your question is somewhat confusing, which may explain the variety of
replies you've received. Let me ask you a few questions first:

Define "Global."

"Global" is a relative term, which refers to scope. For example, to a baby,
"Global Scope" might mean the entire house which is the "world" the baby has
experienced. However, the house is in a neighborhood, so at a slightly
greater age, the child might think of "the world" as their neighborhood.
Since the neighborhood is in a city, the Mayor of the city might think that
"City-wide" is the definition of "Global." The state Governor might think in
terms of the state he/she governs, or even the entire country (all states
together). The president would probably think of the entire world. Or
perhaps, one might think of the Milky Way galaxy as "Global" scope. Or, the
entire universe. So, "Global" must be defined in order to discuss it.

In an application, in the strictest sense of the word, "Global" means
"Application Scope," that is, available everywhere in your web application.
This is entirely different than "Session Scope" which is restricted to those
pages being viewed by a single client in a single browser Session, and also
includes a region of memory in the Application devoted to storing Session
data (the HttpSession class). Still, Session scope can sometimes be termed
"Global," as long as it is understood that the context is Session-wide. In
fact, the term "Global may mean "Global within a class," as in a Page
instance, or "Global within an Assembly" if one is talking about the
Assembly in which a class resides. It's all defined by context.

So, when you entitle your message with the word "Global" and don't define
it, and then add a question about "Session," it muddies the water. What
exactly do you want to limit your scope to? What is the requirement you are
trying to fulfill?

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
"Sylvia A." <sl****@ccc.comwrote in message
news:eI**************@TK2MSFTNGP03.phx.gbl...
How can I define global classes in web application ?

Classes can be set to session variables ?

Thanks


Apr 12 '07 #6

I created a class, for example UserClass, It holds the information about the
logged user, such as, ID, Name, Address, Limits, etc.. Whatever column I
need

This class is created and filled when a specifific page is loaded, such as
login form, after pressing Login button,

After some time in the session, when I go other aspx pages, I wanna get
class info, no need to recreate and fill class from DB,

Such things..

Thanks
"Kevin Spencer" <un**********@nothinks.com>, haber iletisinde þunlarý
yazdý:%2****************@TK2MSFTNGP03.phx.gbl...
Your question is somewhat confusing, which may explain the variety of
replies you've received. Let me ask you a few questions first:

Define "Global."

"Global" is a relative term, which refers to scope. For example, to a
baby, "Global Scope" might mean the entire house which is the "world" the
baby has experienced. However, the house is in a neighborhood, so at a
slightly greater age, the child might think of "the world" as their
neighborhood. Since the neighborhood is in a city, the Mayor of the city
might think that "City-wide" is the definition of "Global." The state
Governor might think in terms of the state he/she governs, or even the
entire country (all states together). The president would probably think
of the entire world. Or perhaps, one might think of the Milky Way galaxy
as "Global" scope. Or, the entire universe. So, "Global" must be defined
in order to discuss it.

In an application, in the strictest sense of the word, "Global" means
"Application Scope," that is, available everywhere in your web
application. This is entirely different than "Session Scope" which is
restricted to those pages being viewed by a single client in a single
browser Session, and also includes a region of memory in the Application
devoted to storing Session data (the HttpSession class). Still, Session
scope can sometimes be termed "Global," as long as it is understood that
the context is Session-wide. In fact, the term "Global may mean "Global
within a class," as in a Page instance, or "Global within an Assembly" if
one is talking about the Assembly in which a class resides. It's all
defined by context.

So, when you entitle your message with the word "Global" and don't define
it, and then add a question about "Session," it muddies the water. What
exactly do you want to limit your scope to? What is the requirement you
are trying to fulfill?

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
"Sylvia A." <sl****@ccc.comwrote in message
news:eI**************@TK2MSFTNGP03.phx.gbl...
>How can I define global classes in web application ?

Classes can be set to session variables ?

Thanks



Apr 14 '07 #7
I am a little curious about your statement. Why do you say so?

As objects is the only thing that you *can* store in the Session object,
it would mean that storing anything there would always be a bad idea.

Juan T. Llibre wrote:
Storing objects in another object (especially in the session object) is *always* a Bad Idea.
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/
===================================
"carion1" <dd******@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
>Storing ref types in Session isn't advisable but here you go.

//create it
myObject myObjectInstance = new myObject();

...do work here...

//dump it into session
Session["myObject"] = myObjectInstance;

//pull it back out of session
myObject myObjectInstance = (myObject)Session["myObject"];

I would store the information needed to re-produce the object and it's
state rather than store the object in Session.

On Apr 12, 8:33 am, "Sylvia A." <sly...@ccc.comwrote:
>>How can I define global classes in web application ?

Classes can be set to session variables ?

Thanks
--
Göran Andersson
_____
http://www.guffa.com
Apr 14 '07 #8
re:
As objects is the only thing that you *can* store in the Session object,
Really ? You mean that plain text can't be stored in the Session object ?

Even if some data *looks* like an object, like MyClass.MyParam.Value,
that's *still* string or numeric data stored in it, so you're not storing the object.

You're storing string/numeric *data*.

re:
it would mean that storing anything there would always be a bad idea
No. Only storing *objects* in the Session object is a bad idea.

String/numeric data is easy to store in the session object and has minimal
impact on system performance, unless they are massive in volume.

You can also store *objects* in the Session Object, besides string/numeric data.
Datasets, arrays and datatables are examples of objects.

However, storing objects in session variables can have a serious performance impact.

If a dataset, for example, is a 500Kb object stored in session, when there's 1,000 users
accessing your session object within the time specified for session timeout, you'll have
a 500MB RAM drain on your server. That's not good.

There's other considerations, too. To be able to *use* the objects,
you'll need to serialize/deserialize them. That takes additional cpu cycles.

For an object like a datatables, they're already marked as serializable.
For custom objects, you'd have to make sure they're serializable.

Using the Cache to store data is much more efficient than storing objects in the Session object.

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/
===================================
"Göran Andersson" <gu***@guffa.comwrote in message news:e5**************@TK2MSFTNGP02.phx.gbl...
>I am a little curious about your statement. Why do you say so?

As objects is the only thing that you *can* store in the Session object, it would mean that
storing anything there would always be a bad idea.

Juan T. Llibre wrote:
>Storing objects in another object (especially in the session object) is *always* a Bad Idea.
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/
===================================
"carion1" <dd******@gmail.comwrote in message
news:11**********************@q75g2000hsh.googleg roups.com...
>>Storing ref types in Session isn't advisable but here you go.

//create it
myObject myObjectInstance = new myObject();

...do work here...

//dump it into session
Session["myObject"] = myObjectInstance;

//pull it back out of session
myObject myObjectInstance = (myObject)Session["myObject"];

I would store the information needed to re-produce the object and it's
state rather than store the object in Session.

On Apr 12, 8:33 am, "Sylvia A." <sly...@ccc.comwrote:
How can I define global classes in web application ?

Classes can be set to session variables ?

Thanks

--
Göran Andersson
_____
http://www.guffa.com

Apr 14 '07 #9
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
For an object like a datatables, they're already marked as serializable.
For custom objects, you'd have to make sure they're serializable.

Using the Cache to store data is much more efficient than storing objects
in the Session object.
Yes, I would agree with that.

For objects which are unique per Session, especially if they are highly
*unlikely* to change for the duration of the Session (e.g. a user profile
etc) I use the Cache. I tend to use the Session object only for tiny
snippets of data which have a very short lifespan e.g. maybe for persisting
data between pages where I don't want to use a QueryString etc...

Since we're on the subject, I'm interested to know your opinion on using the
Application object for persisting data which is always the same for every
user and which *almost* never changes, maybe for years and years... I'm
thinking specifically of country and currency (not exchange rate) data in a
very heavily used international order processing system. Rather than
fetching this data maybe thousands of times a minute every time a user gets
to the checkout page, would you consider it sensible to store it as DataSets
in the Application object e.g.

cmbCountries.DataSource = (DataSet)Application["Countries"];
Apr 14 '07 #10
re:
!your opinion on using the Application object for persisting data which is always
!the same for every user and which *almost* never changes, maybe for years and years.

The Application object is a good place to store data of that type.

The economies of scale inherent in using the Application object, as opposed to
using the Session object, are considerable when dealing with seldom-varying data.

The only caveat is whether the method employed to update the data,
when an update *is* made, can be automated.

A good way to insure that would be to use a Cache and/or SqlCache dependency.
You can cache application data based on database dependencies.

Our good friend, Peter Bromberg, explains how to do this in this article :
http://www.eggheadcafe.com/articles/20060407.asp


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/
===================================
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message news:O2**************@TK2MSFTNGP03.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>For an object like a datatables, they're already marked as serializable.
For custom objects, you'd have to make sure they're serializable.

Using the Cache to store data is much more efficient than storing objects in the Session object.

Yes, I would agree with that.

For objects which are unique per Session, especially if they are highly *unlikely* to change for
the duration of the Session (e.g. a user profile etc) I use the Cache. I tend to use the Session
object only for tiny snippets of data which have a very short lifespan e.g. maybe for persisting
data between pages where I don't want to use a QueryString etc...

Since we're on the subject, I'm interested to know your opinion on using the Application object
for persisting data which is always the same for every user and which *almost* never changes,
maybe for years and years... I'm thinking specifically of country and currency (not exchange rate)
data in a very heavily used international order processing system. Rather than fetching this data
maybe thousands of times a minute every time a user gets to the checkout page, would you consider
it sensible to store it as DataSets in the Application object e.g.
cmbCountries.DataSource = (DataSet)Application["Countries"];

Apr 14 '07 #11
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:eO**************@TK2MSFTNGP02.phx.gbl...
re:
!your opinion on using the Application object for persisting data which
is always
!the same for every user and which *almost* never changes, maybe for
years and years.

The Application object is a good place to store data of that type.

The economies of scale inherent in using the Application object, as
opposed to
using the Session object, are considerable when dealing with
seldom-varying data.
Understood.
The only caveat is whether the method employed to update the data,
when an update *is* made, can be automated.

A good way to insure that would be to use a Cache and/or SqlCache
dependency.
You can cache application data based on database dependencies.

Our good friend, Peter Bromberg, explains how to do this in this article :
http://www.eggheadcafe.com/articles/20060407.asp
Indeed - always good to learn from the master...
Apr 14 '07 #12

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

Similar topics

0
by: Joe Blow via DotNetMonster.com | last post by:
Hello, I have a design problem involving class instances as global variables. To give you my background, I've programmed lots in Java, and most of it has been large class structures. I'm...
12
by: David WOO | last post by:
Hi, I am a newbie on C++, I need to define some global variables which should be accessible to most classes. In the mean time, I don't won't the global variables be modified freely at most of...
6
by: Gunnar Beushausen | last post by:
Hi! I need a class to store the users data (ID, name etc.) that is accessible from anywhere. At application startup the class gets filled with its data about the user. But how can i access...
4
by: Amadelle | last post by:
Hi all and thanks again in advance, What is the best way of defining global constants in a C# application? (A windows application with no windows forms - basically a set of classes). Would it be...
4
by: Simon Harris | last post by:
Hi All, I'm new to ASP.Net, so be gentle! (Plenty of 'classic' ASP experience), just one question... - Am I correct in thinking that global functions are stored in ASCX files? Thanks! ...
22
by: fd123456 | last post by:
Hi Tom ! Sorry about the messy quoting, Google is playing tricks on me at the moment. > Global.asax is where you normally have the Global Application > and Session variables and code to...
7
by: Adam | last post by:
Im trying to add an httphandler for all *.sgf file extensions. I have developed the handler, 1. installed it into the gac 2. added it to the machine.config: <httpHandlers> <add verb="*"...
5
by: eiji | last post by:
Hi folks, I hope this is not "off topic"! :-) Consider the next code: /* Declarations of types that could become platform-dependent */ #define MyChar char #define MyInt int
35
by: Terry Jolly | last post by:
Web Solution Goal: Have a global database connection Why: (There will be 30+ tables, represented by 30+ classes) I only want to reference the database connection once. I put the connection...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.