Solved

How can Site.Master access a variable created by Global.asax?

Posted on 2011-02-10
6
1,175 Views
Last Modified: 2012-05-11
I have a variable I'd like to create in the Global.asax file that I then want to access from the Site.Master file.  How can I do that?  

Thanks,
newbieweb
0
Comment
Question by:newbieweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 500 total points
ID: 34864437
Use a Session variable.

In global.asax sun Session_Start or Application_Start depending on whether you want the value to be unique to the user session or the application as a whole.

Sesssion("mySessionVar") = 'valuetobestored'

Then access it on the master page :

Session("mySessionVar")
0
 

Author Comment

by:newbieweb
ID: 34864534
I get this exception:
"Session state is not available in this context." when I try this first step...

            Session["RDDBAdminDataStore"] = rddbAdminDataStore;
            Session["AppPermissions"] = appPermissions;


Do I first need to create a Session variable?
0
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 500 total points
ID: 34864568
Try

HttpContext.Current.Session.Add(Key, Value)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:newbieweb
ID: 34864675
Both the

Context.Session

and the

HttpContext.Current.Session

are null in Global.Application_Start()
0
 

Accepted Solution

by:
newbieweb earned 0 total points
ID: 34865177
So this threw an exception:
HttpContext.Current.Session.Add(Key, Value)

So, I ended up using:

Context.Items["mySessionVar"] = mySessionVar;

But you got me close.
0
 

Author Closing Comment

by:newbieweb
ID: 34904789
Thanks.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question