Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access properties from global.asax in some other page's code behind

Imagine I have a property defined in global.asax.

public List<string> Roles
{
    get
    {
        ...
    }
    set
    {
        ...
    }
}

I want to use the value in another page. how to I refer to it?

like image 530
minty Avatar asked Oct 30 '08 22:10

minty


2 Answers

You can access the class like this:

((Global)this.Context.ApplicationInstance).Roles
like image 53
Panos Avatar answered Oct 11 '22 08:10

Panos


It looks to me like that only depends on the session - so why not make it a pair of static methods which take the session as a parameter? Then you can pass in the value of the "Session" property from the page. (Anything which does have access to the HttpApplication can just reference its Session property, of course.)

like image 20
Jon Skeet Avatar answered Oct 11 '22 06:10

Jon Skeet