Tuesday, 29 January 2013

How to execute different code if your .NET component is used within web application

I've just discovered a tiny workaround helping me to execute different code inside of .NET component if it is used within a web application:

bool webMode = (System.Web.HttpContext.Current != null);

if (webMode)
{
    // code for web application
}
else
{
    // code for all other types of apps
}

Probably it has some drawbacks and hidden pitfalls but so far it works well...