c# - Edit Web.Config - "System.Net" Section Programmatically? -
i want change "system.net" section in web.config. want add or remove defaultproxy tag according variable in runtime.
<defaultproxy enabled="true" usedefaultcredentials="false"> <module type = "xxx.utils.yyproxy, xxx" /> </defaultproxy> i know, there related posts editing web.config, related connectionstringssection or appsettingssection. there specific classes them in system.configuration package, did not find class related "system.net".
do know quick way handle this? in advance
i found way this. enable or disable defaultproxy tag following code:
configuration config = system.web.configuration.webconfigurationmanager.openwebconfiguration("~"); netsectiongroup netsection = (netsectiongroup)config.getsectiongroup("system.net"); if (string.isnullorempty(model.proxyurl)) netsection.defaultproxy.enabled = false; else netsection.defaultproxy.enabled = true; the key point casting sectiongroup netsectiongroup class.
Comments
Post a Comment