Solved

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

Posted on 2011-02-10
6
1,169 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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