asp.net - How can a .NET code know whether it is running within a web server application? -


i have library code, should aware whether executed in context of web server or standalone application server.

the obvious comes mind check name of application configuration file , if web.config - web server, otherwise - standalone application server.

another way "temporary asp.net files" in path of shadow folder.

but dislike both of these, since seem hacky , fragile. there robust way want?

thanks.

p.s.

one may define dedicated app config setting - iswebserver, dislike more.

edit:

while looking solution problem, think solved 1 - details here

trying solve problem, found solution one. there private method system.configuration.settingspropertyvalue.ishostedinaspnet, need. being private method, not want call (though using reflection), implementation trivial:

private bool ishostedinaspnet() {     return (appdomain.currentdomain.getdata(".appdomain") != null); } 

(according reflector)

looks there special key in app domain data - ".appdomain", set when running in asp.net web server.

i stick that.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -