3

I'm sure I have done this before in the past, but I've been in the docs for a bit, and can't seem to find it again. I need to be able to determine at run time in my business domain what context my application is running in. So that I may do some switching with config files, and use the proper method to determine if I am running in debug or release etc. I was pretty confident it was in System.Environment, but I have not come across it yet.

Matthew Vines
  • 27,253
  • 7
  • 76
  • 97

2 Answers2

7

Very easy method:

bool isWebApp = HttpContext.Current != null;

Works like a charm every time.

Nathan Ridley
  • 33,766
  • 35
  • 123
  • 197
  • 1
    Note that I don't think this will work from inside a worker thread that has been fired off by the web app. In that case though, you could probably pass in a preset variable. – Nathan Ridley May 04 '09 at 15:36
4

I found the way I had done it earlier finally.

bool isWebApp = System.Web.HttpRuntime.AppDomainId != null;

It's much the same as Nathan's response though. Thanks for the reply.

M4N
  • 94,805
  • 45
  • 217
  • 260
Matthew Vines
  • 27,253
  • 7
  • 76
  • 97