How do you access an application variable from a class?

S

Stu

Hi,

If I try to access an application variable from a class I get the error
'Name Application is not declared'.

Is ther any (fairly simple) way of getting round this or do I have to pass
the values in via properties every time I want to use them?

Thank in advance,

Stu

lang: vb.net
 
K

Karl Seguin

HttpContext.Current.Application

note however that if your class isn't running within the context of a
webrequest, HttpContext.Current will return null...defensive coding would
be:

dim context as HttpContext = HttpContext.Current
if context is nothing then
throw new ApplicationException("must be called from a web context")
end if
'can safely access context.Application now...

Karl
 
S

Stu

Many thanks

Karl Seguin said:
HttpContext.Current.Application

note however that if your class isn't running within the context of a
webrequest, HttpContext.Current will return null...defensive coding would
be:

dim context as HttpContext = HttpContext.Current
if context is nothing then
throw new ApplicationException("must be called from a web context")
end if
'can safely access context.Application now...

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top