Is there any way to programmatically change environment variables of OWIN/WebAPI2 host AFTER it started and already running?
There are many samples for creating Windows Service with OWIN self-host app. Its really easy and straightforward: call WebApp.Start<>(..)
in OnStart()
method, catch the IDisposable
returned and then simply dispose it in OnStop
. Ok.
But what am I trying to do is OnPause/OnContinue. I want to change some OWIN environment variable to enable\disable my custom owin middleware that will intercept all requests and simply return 503, for example, when service is paused.
The problem is that IDisposable
returned from WebApp.Start<>(..)
does not contain any public info about service started with it.
And I cannot find any way to access any host/context/settings of running OWIN host that could then be accessed from middlewares after I change'em.
Surely one can simply add middleware/contoller to react on specific web requests, but I don't want even allow possibility of calling these commands from public. Local machine's admin rights - is the only accepted way to call it.