views:

23

answers:

2

Hi, how to differentiate whether a managed library is running in the context of asp.net application or in a executable?

Thanks in adv

+1  A: 

You could check whether HttpContext.Current returns null or not.

Technically, it'll also return null in an ASP.NET application if it's running on a non-worker thread (i.e. if you just go new Thread(SomeProc)) but it should work 99% of the time.

Dean Harding
Speedy! :) It's also possible to "fake" an HttpContext. So I wouldn't rely on this method.
Bryan
A: 

This question doesn't really make a lot of sense. A process is a process. But you may be able to tell if your library is loaded by ASP.NET by checking to see if HttpContext.Current is null.

Bryan