0

I have an web application written in ASP.NET (FW 3.5) (along with some VBScript, this is a legacy app) that uses a utility class in the backend that logs error.

I need to log several values that a user has entered in the front-end. Since the utility class has no access to the front end (or any HTTP services), i created a singleton class within the utility namespace that my front end UI can access and store information about the user.

I guess more specifically, I am wondering if there's a way to store session variables that can be shared across the web application and web services through a class referenced by both of the application and web services. For example, I have an error handling class that is used by both instances that required information about the user. Is there a way to create a per-session singleton to hold that information, so that my error class will have access to the user info? or is this not possible - that i'll need to pass the information around as they are needed?

aggietech
  • 978
  • 3
  • 16
  • 38
  • 1
    This is a duplicate question... kinda. http://stackoverflow.com/questions/2134511/asp-net-singleton – NitroxDM Sep 08 '10 at 22:06

1 Answers1

1

If your singleton implementation uses a Shared variable, your instance will be unique within a single AppDomain.

That said, I would try to avoid using a Singleton simply to facilitate passing data to your utility class.

Larsenal
  • 49,878
  • 43
  • 152
  • 220
  • what would you recommend then? I've seen the previous developer used the configuration manager to pass several settings, but i don't think that's a good idea either. – aggietech Sep 08 '10 at 22:12
  • actually, i just need to store the two values from the current sessions for error reporting. But my reporting method/class is in a different namespace than the web site. – aggietech Sep 08 '10 at 22:14
  • Are you talking about values you literally stored in `Session`? – Larsenal Sep 08 '10 at 22:32
  • yes somewhat, but needing to pass that to a server side utility class. I think i'm just going to move the singleton from the utility class to the web application project ... a little bit more work than i thought of. – aggietech Sep 09 '10 at 13:24
  • i used Session to store my per-session singleton class - thanks! – aggietech Sep 09 '10 at 14:44