Especially in core libraries I tend to not reference System.Web.dll to keep the .NET Framework Client Profile as an option of compilation. I use the following code to figure out if the current running application is a web application

namespace devcoach.Extensions
{
    public static partial class AppDomainExtensions
    {
        public static bool IsWebApp(this AppDomain appDomain)
        {
            var configFile = (string)appDomain.GetData("APP_CONFIG_FILE");
            if (string.IsNullOrEmpty(configFile)) return false;
            return Path.GetFileNameWithoutExtension(configFile).Equals(
                "WEB",
                StringComparison.OrdinalIgnoreCase);
        }
    }
}