[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

(Eric Marc Loebenberg)

1/7/2003 10:03:00 PM

Regarding HttpApplicationState's Application Property, I have a simple
problem that perhaps someone can shed some light on. Simply put, I
cannot access the Application object in these 2 cases :

a) within a class containing events that are not related to an ASP.NET
HTTP request (e.g. file change event)
b) within an XML Web Service called from an event not related to an
ASP.NET HTTP request

In other words, I need to use global application level variables where
there is no HttpContext. It seems that without the HttpContext one
cannot access the Application property.

The question is thus: is there a way to access the dictionary of keyed
objects in the Application State, without the HttpContext?

Thanks!

Eric Marc Loebenberg
CGI
2 Answers

Ryan Gregg

1/8/2003 6:33:00 PM

0

You could always just access the current HttpContext via
System.Web.HttpContext.Current, which seems to be valid for both of your
situations.

Ryan Gregg

"Eric Marc Loebenberg" <emleml@hotmail.com> wrote in message
news:d12fe557.0301071241.2e1e54f1@posting.google.com...
> Regarding HttpApplicationState's Application Property, I have a simple
> problem that perhaps someone can shed some light on. Simply put, I
> cannot access the Application object in these 2 cases :
>
> a) within a class containing events that are not related to an ASP.NET
> HTTP request (e.g. file change event)
> b) within an XML Web Service called from an event not related to an
> ASP.NET HTTP request
>
> In other words, I need to use global application level variables where
> there is no HttpContext. It seems that without the HttpContext one
> cannot access the Application property.
>
> The question is thus: is there a way to access the dictionary of keyed
> objects in the Application State, without the HttpContext?
>
> Thanks!
>
> Eric Marc Loebenberg
> CGI


(Eric Marc Loebenberg)

1/9/2003 1:18:00 AM

0

Ryan,

This does not work since System.Web.HttpContext.Current is null in
both cases. System.Web.HttpContext is only assigned a value in events
triggered by HTTP requests, such as web forms or web services invoked
over the web.

As I stated in the original posting, there is no HTTP Context since
the code is executed through events triggered from file system events
as opposed to ASP http requests.

For now I have a workaround for each case, but they are not too
pretty.

For the file system event, I pass the HttpApplicationState to my
class's constructor and keep it in a class property so I have it when
the file sytem event is called.

For the web service method invoked from the file system event, I again
avoid Application variables (due to the null pointer error I get) and
use a shared static class variable within a separate class to manage
the global variable. It works well but I would have concurrency
problems if I had to do multiple writes through multiple threads
without the neat locking feature of Application variables.

Anyway, I still hope to find a way to access the Application variable
collection.