Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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

Posted on 2011-02-10
Medium Priority
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?  

Question by:newbieweb
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
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 2000 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 :


Author Comment

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?
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 2000 total points
ID: 34864568

HttpContext.Current.Session.Add(Key, Value)
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.


Author Comment

ID: 34864675
Both the


and the


are null in Global.Application_Start()

Accepted Solution

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.

Author Closing Comment

ID: 34904789

Featured Post

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

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.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

670 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