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
Post a Comment