Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.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中将Key添加到appsettings显示加载配置文件时出错:访问路径';c:\inetpub\vobv5_zi.tmp';被拒绝_C#_Vb.net_Web Config_Appsettings - Fatal编程技术网

C# 在web.config中将Key添加到appsettings显示加载配置文件时出错:访问路径';c:\inetpub\vobv5_zi.tmp';被拒绝

C# 在web.config中将Key添加到appsettings显示加载配置文件时出错:访问路径';c:\inetpub\vobv5_zi.tmp';被拒绝,c#,vb.net,web-config,appsettings,C#,Vb.net,Web Config,Appsettings,我正在尝试在C://inetpub文件夹中的web.config中添加appsettings。 Am GET error加载配置文件时出错:对路径“c:\inetpub\vobv5_zi.tmp”的访问被拒绝。(c:\inetpub\web.config.config) 这是我的密码 在Vb中 Dim config As Configuration = ConfigurationManager.OpenExeConfiguration("c:\inetpub\" & sServer &a

我正在尝试在C://inetpub文件夹中的web.config中添加appsettings。 Am GET error加载配置文件时出错:对路径“c:\inetpub\vobv5_zi.tmp”的访问被拒绝。(c:\inetpub\web.config.config)

这是我的密码

在Vb中

Dim config As Configuration = ConfigurationManager.OpenExeConfiguration("c:\inetpub\" & sServer & "\web.config")
        config.AppSettings.Settings.Add(sSearch, "C:\Attachments\")
        config.Save(ConfigurationSaveMode.Modified)
        ConfigurationManager.RefreshSection("appSettings")
在C中#

我试过VB和C。 当my web.config在项目中时,它正在添加appsettings,而my web.config在inetpub中时,它正在抛出错误
加载配置文件时出错:对路径“c:\inetpub\yzb2crt2.tmp”的访问被拒绝。

运行代码的用户(不太清楚您是如何运行代码的)需要对该文件具有写入权限


看起来很清楚,所以您可能需要向我们提供更多信息?

我终于找到了解决方案

  var xmlDoc = new XmlDocument();
        xmlDoc.Load("c:\\inetpub\\web2.config");

        var nodeRegion = xmlDoc.CreateElement("add");
        nodeRegion.SetAttribute("key", "Region");
        nodeRegion.SetAttribute("value", "Canterbury");

        xmlDoc.SelectSingleNode("//appSettings").AppendChild(nodeRegion);
        xmlDoc.Save("c:\\inetpub\\web2.config");

        ConfigurationManager.RefreshSection("appSettings");

通过此操作,我将appsettings添加到inetpub的web.config文件中。

从何处调用此代码?你给哪个用户烫发了?为web.config文件提供perms可能不够(因为它似乎是先写入tmp文件)。如果您在本地运行,请尝试将“Everyone”添加到文件夹的完全控制中(并在测试后立即删除),如果可以,请尝试运行代码的用户(并删除)。当我在以管理员身份运行模式下运行visual studio 2012时,我没有收到任何错误。。但是应用程序密钥没有添加到应用程序设置中。我添加了所有人并在以管理员身份运行模式下启动我的visual studio,我没有收到任何错误,但是应用程序设置没有添加受保护的无效页面加载(对象发件人,事件参数e){var config=ConfigurationManager.OpenExeConfiguration(“c:\\inetpub\\web.config”);config.AppSettings.Settings.Add(“OS”,“Linux”);config.Save(ConfigurationSaveMode.Full);ConfigurationManager.RefreshSection(“AppSettings”);}我正在测试我的页面load@Mark…你能看看这个吗
  var xmlDoc = new XmlDocument();
        xmlDoc.Load("c:\\inetpub\\web2.config");

        var nodeRegion = xmlDoc.CreateElement("add");
        nodeRegion.SetAttribute("key", "Region");
        nodeRegion.SetAttribute("value", "Canterbury");

        xmlDoc.SelectSingleNode("//appSettings").AppendChild(nodeRegion);
        xmlDoc.Save("c:\\inetpub\\web2.config");

        ConfigurationManager.RefreshSection("appSettings");