0

I am writing a class library and want to perform some conditional processing if the client/host application using the library is an ASP.NET application.

I am thinking that the simplest way of checking that would be simply to set a static reference to System.Web.dll in my library and then to check if the HttpContext object is null or not. If it is not null, then we know that we're running in the context of a Web app.

However, I am not sure if this is a fool-proof method. Is there a more sophisticated approach?

Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336

1 Answers1

1

HttpContext may be null in certain scenarios... And it's thread static, so not reliable in multithreaded scenarios.

You could consider using the HostingEnvironment class.

Jeff
  • 35,755
  • 15
  • 108
  • 220