Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to pass Application.Item value back to class?

Reply
Thread Tools

How to pass Application.Item value back to class?

 
 
=?Utf-8?B?YWRvbGYgZ2FybGlj?=
Guest
Posts: n/a
 
      11-11-2004
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.item 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
 
Reply With Quote
 
 
 
 
Scott Allen
Guest
Posts: n/a
 
      11-11-2004
Hi Adolf:

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

HttpContext.Current.Application["foo"] = o;

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

On Thu, 11 Nov 2004 04:29:06 -0800, adolf garlic
<(E-Mail Removed)> 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.
>
>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.item 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


 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      11-11-2004
> 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.HttpContext.Current.Application.

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

"adolf garlic" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.item 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



 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      11-11-2004
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.HttpContext, 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.item 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



 
Reply With Quote
 
lezmark
Guest
Posts: n/a
 
      11-11-2004
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:(E-Mail Removed)...
> Hi Adolf:
>
> As long as the class is working during a web request, it can use
> System.Web.HttpContext.Current to tap into the context of the web
> request. For example:
>
> HttpContext.Current.Application["foo"] = o;
>
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
>
> On Thu, 11 Nov 2004 04:29:06 -0800, adolf garlic
> <(E-Mail Removed)> 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.
>>
>>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.item 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

>



 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      11-11-2004
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.Current, 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.Current and referencing
HttpApplicationState. 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" <(E-Mail Removed)> 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?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Variable Input on procedure - pass by value or pass by reference? Tricky VHDL 0 03-19-2009 03:59 PM
Variable Input on procedure - pass by value or pass by reference? Tricky VHDL 0 03-19-2009 03:58 PM
pass by value or pass by address? Vols C++ 3 04-27-2008 11:40 PM
Problem understanding pass by value and pass by reference of arrays and what happens in the memory venkatagmail C++ 11 10-03-2007 02:00 PM
Pass by reference / pass by value Jerry Java 20 09-09-2005 06:08 PM



Advertisments