Solved

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

Posted on 2011-02-10
6
1,156 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
  • 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now