应用程序主机配置错误:由于IIS共享配置,无法写入配置文件,权限不足。

18

我在一个Windows服务中使用Microsoft.Web.Administration.ServerManager类来管理网站。

我的代码中使用模拟身份,使用管理员用户,该用户有权修改我的applicationHost.config文件。但是当我执行.CommitChanges();时,总是出现以下错误。

以下是我的代码示例。

  using (ServerManager svr = ServerManager.OpenRemote(args.IISName))
      {           
        Site currentSite = svr.Sites.Where(item => item.Id == args.WebSite.Id).FirstOrDefault();            
        currentSite.Applications[0].VirtualDirectories[0].PhysicalPath = args.WebSite.PhysicalPath;
        svr.CommitChanges();           

      }

我发现了这个解决方案,但我的dcom属性对象被锁定了。

您的应用程序发生未处理的异常。如果单击“继续”,该应用程序将忽略此错误并尝试继续运行。如果单击“退出”,该应用程序将立即关闭。文件名\?\UNC[MY PATH]\applicationHost.config 错误:由于权限不足而无法写入配置文件。

我的设置是Windows 2008 R2,IIS 7.5,框架3.5,我的applicationHost.config位于SAN上。

我可以尝试什么?

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.UnauthorizedAccessException: Filename: \\?\[MY PATH]\applicationHost.config
Error: Cannot write configuration file due to insufficient permissions


   at Microsoft.Web.Administration.Interop.IAppHostWritableAdminManager.CommitChanges()
   at Microsoft.Web.Administration.ConfigurationManager.CommitChanges()
   at Microsoft.Web.Administration.ServerManager.CommitChanges()
   at Nms.IIS.Business.Manager.IISManager70.UpdateWebSiteEntity(UpdateWebSiteEntityArgs args)
   at Nms.IIS.Business.Service.IISService70.UpdateWebSiteEntity(UpdateWebSiteEntityArgs args)
   at IISSwitcher.Form1.btnProccess_Click(Object sender, EventArgs e) in C:\Form1.cs:line 70
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4952 (win7RTMGDR.050727-4900)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
IISSwitcher
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file://[mypatch]/Altitude3%20Transfert/IISDirectorySwitch/IISSwitcher.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Nms.IIS.Business
    Assembly Version: 1.0.295.8874
    Win32 Version: 1.0.295.8874
    CodeBase: file://[mypatch]/Altitude3%20Transfert/IISDirectorySwitch/Nms.IIS.Business.DLL
----------------------------------------
Nms.Core
    Assembly Version: 1.0.1954.8874
    Win32 Version: 1.0.1954.8874
    CodeBase: file://[mypatch]/Altitude3%20Transfert/IISDirectorySwitch/Nms.Core.DLL
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Microsoft.Practices.Unity
    Assembly Version: 1.2.0.0
    Win32 Version: 1.2.0.0
    CodeBase: file://[mypatch]/Altitude3%20Transfert/IISDirectorySwitch/Microsoft.Practices.Unity.DLL
----------------------------------------
Microsoft.Practices.Unity.Interception
    Assembly Version: 1.2.0.0
    Win32 Version: 1.2.0.0
    CodeBase: file://Microsoft.Practices.Unity.Interception.DLL
----------------------------------------
Microsoft.Practices.ObjectBuilder2
    Assembly Version: 2.2.0.0
    Win32 Version: 2.2.0.0
    CodeBase: file://Microsoft.Practices.ObjectBuilder2.DLL
----------------------------------------
System.Core
    Assembly Version: 3.5.0.0
    Win32 Version: 3.5.30729.4926 built by: NetFXw7
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Core/3.5.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
Nms.Core.resources
    Assembly Version: 1.0.1954.8874
    Win32 Version: 1.0.1954.8874
    CodeBase: file://Nms.Core.resources.DLL
----------------------------------------
Unity_ILEmit_InterfaceProxies
    Assembly Version: 0.0.0.0
    Win32 Version: 1.2.0.0
    CodeBase: file://Microsoft.Practices.Unity.Interception.dll
----------------------------------------
Microsoft.Web.Administration
    Assembly Version: 7.0.0.0
    Win32 Version: 6.1.7600.16385
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.Web.Administration/7.0.0.0__31bf3856ad364e35/Microsoft.Web.Administration.dll
----------------------------------------
System.Runtime.Serialization
    Assembly Version: 3.0.0.0
    Win32 Version: 3.0.4506.4926 (NetFXw7.030729-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Runtime.Serialization/3.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
6个回答

42

在我们的情况下,服务器磁盘已满。我们添加了额外的磁盘空间,问题得到解决。


1
这对我们来说也是如此。 - Chad K
2
这通常是情况。我已经看到这种情况很多次,因为IIS日志文件可以快速增长。特别是如果涉及的站点是SharePoint。 - Michael Adamission
3
这是最有可能的原因,因此应该被接受为正确答案。 - Adrian Rosca
感谢让我回归现实的编程。 - Grijan
和我的一样。谢谢。 - Hamid Noahdi

16

我从我的解决方案中删除了现有的applicationhost.config文件,并重新加载了解决方案。解决方案自己创建了新的ApplicationHost.config文件。

这解决了我的问题。


1
这对我有用。另外,请注意错误消息中提到的applicationhost.config的位置。 - Mo D Genesis
那个文件在.vs文件夹里,我最终决定删除整个文件夹,这也起作用。 - Cryptc

9
要解锁你的dcom属性对象,你只需要执行两个步骤。
第一步 - 授予“Ahadmin.dll”文件上的“完全控制”权限:
1. 进入IIS服务器并浏览到“c:\windows\system32\”文件夹。 2. 找到“Ahadmin.dll”文件并右键单击打开属性框。 3. 转到“安全”选项卡并授予NT用户“完全控制”权限。 4. 如果无法授予“完全控制”权限,请转到“所有者”选项卡,并添加你的NT用户或管理员组,然后点击“应用”,再返回“安全”选项卡以授予“完全控制”权限。
第二步 - 授予注册表键上的“完全控制”权限:
1. 在IIS服务器上打开“注册表编辑器”(运行命令:regedit)。 2. 将光标放在左侧窗格中的根目录上。 3. 打开查找框并输入“ahadmin”,然后点击查找。 4. 注册表将在右侧窗格中找到一个键。右键单击该键的父文件夹并打开属性框。 5. 转到“安全”选项卡并授予NT用户“完全控制”权限。 6. 如果无法授予“完全控制”权限,请转到“所有者”选项卡,并添加你的NT用户或管理员组,然后点击“应用”,再返回“安全”选项卡以授予“完全控制”权限。
现在你可以编辑你的dcom属性对象了。如果dcom属性对象仍然被锁定,请等待几分钟并重试。完成后,只需按照此处的步骤进行操作即可。

这对我有用 - 奇怪的是,当应用属性时,WCF自动启动会抱怨。错误:“保存配置时发生错误。查看详细信息以获取其他信息。在关闭此对话框后,可以重新应用更改。文件名:\?\C:\Windows\system32\inetsrv\c. . .\applicationHost.config 错误:无法写入配置文件” - SliverNinja - MSFT

4
请确保项目文件夹没有加密。Visual Studio在处理加密文件夹时存在问题。
我的用户文件夹被加密,因此项目无法打开,直到我将这些文件夹标记为非加密状态。很遗憾VS没有提供有意义的错误提示,告诉你需要从项目文件夹中移除加密。
要移除加密,请右键单击项目文件夹,选择“高级”,然后取消选中“加密”复选框。将更改应用于文件夹本身及其所有嵌套文件夹和文件。
请参考以下图片:“禁用加密”(Disable encryption)。

这对我来说就是问题所在。 - Ebikeneser

1

请确保文件的安全设置和共享的安全设置都允许模拟用户修改文件。由于您正在使用 UNC 路径访问配置文件,因此需要在两个级别上获取权限。


沿着这条线路,检查文件的有效权限(类似于右键单击、属性、安全、高级、有效权限)。这应该给您提供用户在文件系统级别(NTFS)可以执行哪些操作的权威列表。 - Nelson Rothermel

0
如果虚拟目录映射到共享文件夹,请查看共享的权限。在Windows 7 / w2k8下,默认情况下创建共享时具有以下权限: Everyone(读取)。 将共享权限更改为: Everyone(FullControl)
这样可以使IIS通过共享执行所需操作,因为它没有使用完整的物理路径。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接