How do you access an application variable from a class?

  • Thread starter Thread starter Stu
  • Start date Start date
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
 
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
 
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
 
Back
Top