C# 从代码隐藏编辑web.config中的httpErrors部分
是否可以从代码隐藏中编辑web.config文件的“system.webServer”部分中的“httpErrors” 使用以下命令时,Im将获得空值:C# 从代码隐藏编辑web.config中的httpErrors部分,c#,web-config,code-behind,C#,Web Config,Code Behind,是否可以从代码隐藏中编辑web.config文件的“system.webServer”部分中的“httpErrors” 使用以下命令时,Im将获得空值: ConfigurationSection测试=(ConfigurationSection)config.GetSection(“system.webServer/httpErrors”) 我想更改errorMode和existingResponse的值。还要删除嵌套在“httpErrors”中的任何现有“删除”或“错误”偏差 由此: <h
ConfigurationSection测试=(ConfigurationSection)config.GetSection(“system.webServer/httpErrors”)代码>
我想更改errorMode和existingResponse的值。还要删除嵌套在“httpErrors”中的任何现有“删除”或“错误”偏差
由此:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" />
<error statusCode="404" path="/ErrorPages/NotFound.aspx" />
</httpErrors>
为此:
<httpErrors errorMode="Detailed" existingResponse="Auto" />
您可以使用以下代码:
var configuration = WebConfigurationManager.OpenWebConfiguration("~");
var section = (ConnectionStringsSection)configuration.GetSection("connectionStrings");
section.ConnectionStrings["MyConnectionString"].ConnectionString = "Data Source=...";
configuration.Save();
有关更多信息,请查看