473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to get Application State from a class

Hi:

In Application_Start method in the global.asax, I created an application
state: Application["test"]="...".

I can get the value from the each page, but I cannot get it in the class
that is called from a page. I always get an error as:

Object reference not set to an instance of an object.
......
I have to make the class inherit from System.Web.UI.Page class? Any other
way?

Thanks

Q.
Nov 18 '05 #1
2 999
Simply use this full namespace from within your class:
System.Web.HttpContext.Current.Application["test"]

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

"Quentin Huo" <q.***@manyworlds.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi:

In Application_Start method in the global.asax, I created an application
state: Application["test"]="...".

I can get the value from the each page, but I cannot get it in the class
that is called from a page. I always get an error as:

Object reference not set to an instance of an object.
.....
I have to make the class inherit from System.Web.UI.Page class? Any other
way?

Thanks

Q.

Nov 18 '05 #2
Take a look at the HttpContext class in the System.Web namespace. It should
have the answer you're looking for.

http://msdn.microsoft.com/library/en...asp?frame=true

You'll need to reference System.Web.HttpContext.Current to get the reference
to the current HttpContext object.

"Quentin Huo" <q.***@manyworlds.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi:

In Application_Start method in the global.asax, I created an application
state: Application["test"]="...".

I can get the value from the each page, but I cannot get it in the class
that is called from a page. I always get an error as:

Object reference not set to an instance of an object.
.....
I have to make the class inherit from System.Web.UI.Page class? Any other
way?

Thanks

Q.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
0
by: Brett | last post by:
I am working with vb.net in a asp.net application. I have created a config file in xml format. The goal is to be able to change the config file without having to recompile the entire...
4
by: BB | last post by:
Hello all, I might be missing something here, but am trying to understand the difference between using application-level variables--i.e. Application("MyVar")--and global variables--i.e. public...
20
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business...
8
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.