Application object

  • Thread starter Thread starter Alexander Kaplunov
  • Start date Start date
A

Alexander Kaplunov

Happy New Year everybody!

I have a asp.net web application, which has aspx files with code-behind and
also some .cs files. My question is how can I get to Application object
within C# objects (.cs files)? I can write the code...

string str = (string)Application["test"];

and it compiles OK but I get the runtime error...

System.NullReferenceException: Object reference not set to an instance of
an object.


Any ideas?

Here is a more detailed description of what I'm trying to do...

I want to store an SqlConnection in an Application object and then have the
data extracted from the database by another object, which only deals with
the database. Is this even the right way of doing it?

Any suggestions would be greatly appriciated.

Thanks,
Alex.
 
Or better yet:

System.Web.HttpContext.Current.Cache

The Application object is not thread-safe, but the Application Cache IS, and
offers more granular control over the objects in it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Steve C. Orr said:
Use this:
use System.Web.HttpContext.Current.Application

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com



Alexander Kaplunov said:
Happy New Year everybody!

I have a asp.net web application, which has aspx files with code-behind and
also some .cs files. My question is how can I get to Application object
within C# objects (.cs files)? I can write the code...

string str = (string)Application["test"];

and it compiles OK but I get the runtime error...

System.NullReferenceException: Object reference not set to an instance of
an object.


Any ideas?

Here is a more detailed description of what I'm trying to do...

I want to store an SqlConnection in an Application object and then have the
data extracted from the database by another object, which only deals with
the database. Is this even the right way of doing it?

Any suggestions would be greatly appriciated.

Thanks,
Alex.
 
Back
Top