Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1185
  • Last Modified:

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

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
newbieweb
Asked:
newbieweb
  • 4
  • 2
3 Solutions
 
Paul JacksonCommented:
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
 
newbiewebSr. Software EngineerAuthor Commented:
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
 
Paul JacksonCommented:
Try

HttpContext.Current.Session.Add(Key, Value)
0
Industry Leaders: 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!

 
newbiewebSr. Software EngineerAuthor Commented:
Both the

Context.Session

and the

HttpContext.Current.Session

are null in Global.Application_Start()
0
 
newbiewebSr. Software EngineerAuthor Commented:
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
 
newbiewebSr. Software EngineerAuthor Commented:
Thanks.
0

Featured Post

Technology Partners: 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!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now