Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从代码隐藏编辑web.config中的httpErrors部分_C#_Web Config_Code Behind - Fatal编程技术网

C# 从代码隐藏编辑web.config中的httpErrors部分

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

是否可以从代码隐藏中编辑web.config文件的“system.webServer”部分中的“httpErrors”

使用以下命令时,Im将获得空值:

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();
有关更多信息,请查看