I am wondering if anyone has a method to determine if a thread is running in a web environment.
HttpContext.Current
not reliable because I do these checks in the background thread where there is no HttpContext. It seems
HttpRuntime.AppDomainAppId
pretty reliable (if it is zero, then I'm not in a web application), but I'm wondering if anyone else has any proven method.
By the way, I will use this for a variety of things. For example, this code:
if (HttpRuntime.AppDomainAppId != null) { config = WebConfigurationManager.OpenWebConfiguration("~"); } else { config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); }
thanks
Joni
source share