I have a library code, which should be aware whether it is executed in the context of a web server or standalone application server.
The obvious that comes to mind i
You can check for
HttpContext.Current
If it is not null then it is run from a web app.
See HttpContext.Current Property