在后面的代码中更改web.config设置 [英] change web.config settings in code behind
问题描述
我使用第三方上传控件,并且web.config中的设置很少
i m using a third party upload control and there r few settings in web.config
<uploadSettings allowedFileExtensions=".pdf,.xls,.doc,.zip,.rar,.jpg" scriptPath="upload_scripts" imagePath="" cssPath="upload_styles" enableManualProcessing="true" showProgressBar="true" showCancelButton="true"/>
现在,我想从后面的代码中更改这些设置,例如,我想将showcancelbutton ="false"
now i want to change these settings from code behind e.g i want to make showcancelbutton="false"
我该怎么做
推荐答案
由于它是Web应用程序,因此您需要更改.我将使用WebConfigurationManager.
Since it's a web application you want to change I'd go with the WebConfigurationManager.
如果您要更改的配置值在单独的部分中,则需要先获取该部分:
If the configuration value you are about to change is in a separate section you need to get that section first:
var myConfiguration = (Configuration)WebConfigurationManager.OpenWebConfiguration("~");
var section = (MySectionTypeHere)myConfiguration.GetSection("system.web/mySectionName");
//Change your settings here
myConfiguration.Save();
请记住,每次更改web.config时都会重新启动Web应用程序.
Keep in mind that the web application will be restarted each time you change the web.config.
在此处可以找到更详细的文章.
An article explaining it more in detail is available here.
这篇关于在后面的代码中更改web.config设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!