473,545 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pass Application.Ite m value back to class?

Suggestions please for strategy to share values across app.

Scenario:

I have an asp.net app that uses some com components along with .net classes.

Configuration settings for various things are held in an xml file to which
the com has access. The xml file has different nodes for different instances
(dev,uat1,uat2 etc..) there is a flag attribute to show current instance.

The asp.net app loads the xml in global.asax and extracts a bunch of data
into Application.ite m variables.

What I can't then do is access the Application variables from any classes in
the app that are not associated with a web page.

Yes I can put the values into web.config but this present 2 problems
- you need to write a messy section handler with namevalue object to read
any data
- the com can't see the file (well it can but for admin purposes you
shouldn't need to duplicate values - more scope for going wrong)

Can anyone think of a way in which I can pass Application variables back to
a class?

Thanks
Nov 18 '05 #1
5 1902
Hi Adolf:

As long as the class is working during a web request, it can use
System.Web.Http Context.Current to tap into the context of the web
request. For example:

HttpContext.Cur rent.Applicatio n["foo"] = o;

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 11 Nov 2004 04:29:06 -0800, adolf garlic
<ad*********@di scussions.micro soft.com> wrote:
Suggestions please for strategy to share values across app.

Scenario:

I have an asp.net app that uses some com components along with .net classes.

Configuratio n settings for various things are held in an xml file to which
the com has access. The xml file has different nodes for different instances
(dev,uat1,ua t2 etc..) there is a flag attribute to show current instance.

The asp.net app loads the xml in global.asax and extracts a bunch of data
into Application.ite m variables.

What I can't then do is access the Application variables from any classes in
the app that are not associated with a web page.

Yes I can put the values into web.config but this present 2 problems
- you need to write a messy section handler with namevalue object to read
any data
- the com can't see the file (well it can but for admin purposes you
shouldn't need to duplicate values - more scope for going wrong)

Can anyone think of a way in which I can pass Application variables back to
a class?

Thanks


Nov 18 '05 #2
> Can anyone think of a way in which I can pass Application variables back
to
a class?
It's important that you grip them over the laces. Put a good spin on them,
and just heave with all your might. Be sure to follow through. From that
point, it's up to the class to catch them.

;-)

Actually, if I understand you correctly, you want to ACCESS application
variables FROM a class, right? Now, in .Net, everything is a class, so I'm
going to have to go out on a limb and guess that what you are referring to
is classes that are not Page classes. In that case, you can access the
Application as System.Web.Http Context.Current .Application.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"adolf garlic" <ad*********@di scussions.micro soft.com> wrote in message
news:46******** *************** ***********@mic rosoft.com... Suggestions please for strategy to share values across app.

Scenario:

I have an asp.net app that uses some com components along with .net classes.
Configuration settings for various things are held in an xml file to which
the com has access. The xml file has different nodes for different instances (dev,uat1,uat2 etc..) there is a flag attribute to show current instance.

The asp.net app loads the xml in global.asax and extracts a bunch of data
into Application.ite m variables.

What I can't then do is access the Application variables from any classes in the app that are not associated with a web page.

Yes I can put the values into web.config but this present 2 problems
- you need to write a messy section handler with namevalue object to read
any data
- the com can't see the file (well it can but for admin purposes you
shouldn't need to duplicate values - more scope for going wrong)

Can anyone think of a way in which I can pass Application variables back to a class?

Thanks

Nov 18 '05 #3
I just noticed that your message did mention that your prlbme was with
classes that are "not associated with a web page." So, I guessed correctly,
even though I missed that the first time I read your message. In fact, for
future reference, classes that have direct access to the current HttpContext
are any classes which implement IHttpHandler (such as Page) or IHttpModule.
Other classes must refer to the static "Current" member of
System.Web.Http Context, and of course, they must be used in that context in
order to access it (such as in a web application or Web Service).

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"adolf garlic" <ad*********@di scussions.micro soft.com> wrote in message
news:46******** *************** ***********@mic rosoft.com...
Suggestions please for strategy to share values across app.

Scenario:

I have an asp.net app that uses some com components along with .net classes.
Configuration settings for various things are held in an xml file to which
the com has access. The xml file has different nodes for different instances (dev,uat1,uat2 etc..) there is a flag attribute to show current instance.

The asp.net app loads the xml in global.asax and extracts a bunch of data
into Application.ite m variables.

What I can't then do is access the Application variables from any classes in the app that are not associated with a web page.

Yes I can put the values into web.config but this present 2 problems
- you need to write a messy section handler with namevalue object to read
any data
- the com can't see the file (well it can but for admin purposes you
shouldn't need to duplicate values - more scope for going wrong)

Can anyone think of a way in which I can pass Application variables back to a class?

Thanks

Nov 18 '05 #4
Hi,
Just a thought, Can't you pass the application settings as a parameter to
the caller?
As the context is entirely different( I mean the web context and your
processing classes), or in other words ,configuration is different from
processing classes, will you be able to change your code to accept
application settings as parameters from the asp.net page?
--
Arul

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:be******** *************** *********@4ax.c om...
Hi Adolf:

As long as the class is working during a web request, it can use
System.Web.Http Context.Current to tap into the context of the web
request. For example:

HttpContext.Cur rent.Applicatio n["foo"] = o;

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 11 Nov 2004 04:29:06 -0800, adolf garlic
<ad*********@di scussions.micro soft.com> wrote:
Suggestions please for strategy to share values across app.

Scenario:

I have an asp.net app that uses some com components along with .net
classes.

Configurati on settings for various things are held in an xml file to which
the com has access. The xml file has different nodes for different
instances
(dev,uat1,uat 2 etc..) there is a flag attribute to show current instance.

The asp.net app loads the xml in global.asax and extracts a bunch of data
into Application.ite m variables.

What I can't then do is access the Application variables from any classes
in
the app that are not associated with a web page.

Yes I can put the values into web.config but this present 2 problems
- you need to write a messy section handler with namevalue object to read
any data
- the com can't see the file (well it can but for admin purposes you
shouldn't need to duplicate values - more scope for going wrong)

Can anyone think of a way in which I can pass Application variables back
to
a class?

Thanks

Nov 18 '05 #5
Yes, you can always pass those items as parameters. I'd avoid passing
a reference to the entire Application collection as that can be easily
retreived with HttpContext.Cur rent, but if I wanted to decouple my
classes from being used strictly in an asp.net app I'd pass the values
along and avoid HttpContext.Cur rent and referencing
HttpApplication State. You could always package the parameters into a
Hashtable or pass them individually.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 11 Nov 2004 08:55:37 -0600, "lezmark" <le*****@cox.ne t> wrote:
Hi,
Just a thought, Can't you pass the application settings as a parameter to
the caller?
As the context is entirely different( I mean the web context and your
processing classes), or in other words ,configuration is different from
processing classes, will you be able to change your code to accept
application settings as parameters from the asp.net page?


Nov 18 '05 #6

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

Similar topics

10
2048
by: Doug Jordan | last post by:
I am fairly new to Python. This should be an easy answer but I cannot get this to work. The code is listed below. I know how to do this in C, Fortran, and VB but it doesn't seem to work the same way here. I would appreciate any help. #try this to pass a list to a function and have the function return #a variable #this works list= def...
8
3353
by: Brian F | last post by:
Exactly what the subject says. I have an ASP page that I want my C# windows application to open in Internet Explorer, and if possible have it send along a list of values from a list box. Thank you.
0
1878
by: Melson | last post by:
Hi Can anyone help me with this problem. I've a form1(entry form) with datagrid which bound to a dataset (datagrid.setdatabinding(dataset,"table")). I've a public class Capturekey in form1 which capture key entered in the datagrid cell. I've another form2(product code form) which has a listview display product code. My problem is how can...
12
11031
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed!...
0
7479
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7411
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7669
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7926
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3468
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1028
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.