Click here to Skip to main content
14,668,498 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,

Is it possible to access a variable created in session_start() method of the global.asax file on a aspx.cs page ?

Thanks on advance !

Regards,
Divya
Posted
Updated 26-Oct-10 2:18am
v2
Comments
Sandeep Mewara 26-Oct-10 8:09am
   
Variable created in a page? NO!
if you mean session, do update the question.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

If you create a variable inside the scope of the session_start() method, it will only be available inside that method.

If you store a value in application or session state, those are accessible throughout your application. For example:

string myAppTitle = (string)Application["appTitle"]'


Here's a primer[^] on application state from MSDN.

Cheers.
   
Comments
Divymital 26-Oct-10 8:46am
   
Thanks for your response. I dont want to have the object in session or in application. My requirement is to access some values specific to each user across pages. I dont want to go for session var or using previous page methods as they are heavy and previos page will have all its vars/view states etc.

So I was looking for a technique by which I can just store the values in an object some where and keep retriving teh same object on other pages that too specific for each user.

Thanks again.

Cheers ~
Divya
TheyCallMeMrJames 26-Oct-10 9:18am
   
Why makes you think it's "heavy"? I respectfully disagree. If it's specific to each user, the session state is exactly where you want it. Session state is highly optimized.
Divymital 26-Oct-10 9:39am
   
It is just because big chunk of people use the application at the same time thats why I was wondering is keeping the objects in teh session could place load on server and it will carry forward till the object ends.

Is keeping objects in session appriciated or a good programming practise ? or is there any other approach where we can use teh object by smoe other way which will keep server load less..

Thank you very much for your kind response .. :).. This helped me.

Regards,
Divya
TheyCallMeMrJames 26-Oct-10 9:54am
   
It won't add load, per se, but if the objects are big they will consume memory. Your options are basically to keep the objects in memory, or persist them somehow (disk, database). If you persist them, you get your memory back, but then have the expense of writing/reading to disk or a database. (There are other factors based on scale, but you can definitely start here.)

If you have an object that is created for a user, used throughout the time they are on the site, and needs to be associated only to one user, then session state is where you want the data.

Hope this helps! ...and hey, thanks for the vote! ;o)

Cheers.
raju melveetilpurayil 26-Oct-10 16:03pm
   
good one

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100