You should parameterize this information and pass that to the class/methods you want to use.
You can't determine (in a reliable way) if one application is a web application or console application because they are not mutally exclusive. A console application can behave as a web application too, take OWIN as an example.
If you insist to do it automatically you define and use an Attribute in the executable assembly:
[AttributeUsage(AttributeTargets.Assembly)]
public class AppModelAttribute : Attribute {
public ModelType Model {get;private set} // This one can be an enum type with values Web, Console
public AppModel(ModelType type)
{
this.Model = type;
}
}
Add this assembly in your executing assembly:
[assembly: AppModelAttribute(ModelType.Web)]
Then you can query this attribute and determine if the executing assembly is Web or Console:
var attributes = assembly
.GetCustomAttributes(typeof(AppModelAttribute), false)
.Cast<AppModelAttribute>();
Above query is taken from here.
EDIT: I mean a console application can start as a web server and behave as a regular web application, for example HttpServer class can be used in any kind of application and it lets you answer http messages (GET, POST etc). OWIN is an example of a console application behaving as a web application.
You can however define a web application as an application running on IIS in your context. Then you need to somehow analyze the process and see if it actually is hosted by IIS, but that would be certainly an overkill.