c# - How to change HttpRuntime settings (eg WaitChangeNotification) at runtime? -
it easy set settings in web.config typing them xml file. however, set settings @ runtime.
specifically want set system.web/httpruntime/waitchangenotification setting.
i've tried this, throws error says configuration readonly.
var section = httpcontext.current.getsection("system.web/httpruntime") system.web.configuration.httpruntimesection; section.waitchangenotification = 6;
it's not idea, entirely possible using reflection.
here code example of injecting soap extension web services section of app config:
// turn read field non-readonly webservicessection wss = webservicessection.current; soapextensiontypeelement e = new soapextensiontypeelement(typeof (traceextension), 1, prioritygroup.high); fieldinfo readonlyfield = typeof(system.configuration.configurationelementcollection).getfield("breadonly", bindingflags.nonpublic | bindingflags.instance); readonlyfield.setvalue(wss.soapextensiontypes, false); // bind web services section of config wss.soapextensiontypes.add(e); // restore original other things don't break methodinfo resetmethod = typeof(system.configuration.configurationelementcollection).getmethod("resetmodified", bindingflags.nonpublic | bindingflags.instance); resetmethod.invoke(wss.soapextensiontypes, null); methodinfo setreadonlymethod = typeof(system.configuration.configurationelementcollection).getmethod("setreadonly", bindingflags.nonpublic | bindingflags.instance); setreadonlymethod.invoke(wss.soapextensiontypes, null);
obviously not retrospective affect values pulled out of config after it's been done.
...and once again, don't want this, possible.
Comments
Post a Comment