.net - How to access the HttpServerUtility.MapPath method in a Thread or Timer? -
i use system.timers.timer
in asp.net application , need use httpserverutility.mappath
method seems available via httpcontext.current.server.mappath
. problem httpcontext.current
null
when timer.elapsed
event fires.
is there way reference httpserverutility object ? inject in class' constructor. safe ? how can sure won't garbage collected @ end of current request?
thanks!
it's possible use hostingenvironment.mappath()
instead of httpcontext.current.server.mappath()
i haven't tried yet in thread or timer event though.
some (non viable) solutions considered;
the method care on
httpserverutility
mappath
. alternative useappdomain.currentdomain.basedirectory
, build paths this. but fail if app uses virtual directories (mine does).another approach: add paths need the
global
class. resolve these paths inapplication_start
.
Comments
Post a Comment