applicationHost.config错误:由于IIS共享配置的权限不足,无法写入配置文件

时间:2011-02-17 15:31:19

标签: c# security iis file-permissions windows-server-2008-r2

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

我在我的代码中使用模拟,使用管理员用户,用户有权修改我的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();           

      }

我找到this solutions,但我的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 个答案:

答案 0 :(得分:12)

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

它解决了我的问题。

答案 1 :(得分:11)

在我们的例子中,服务器磁盘已满。我们添加了额外的磁盘空间,问题就解决了。

答案 2 :(得分:7)

要解锁您的dcom属性对象,您只需要执行两个步骤。

第1步 - 在'Ahadmin.dll'上授予您'完全控制权':

  • 转到IIS服务器并浏览到文件夹'c:\ windows \ system32 \'
  • 找到'Ahadmin.dll'并右键单击它以打开属性框
  • 转到“安全”标签并授予您的NT用户“完全控制”
  • 如果您无法授予“完全控制权”,请转到“所有者”标签 并添加您的NT用户或您所属的管理员组,然后单击“应用” 然后返回“安全”标签以授予您“完全控制权”

步骤2 - 在注册表项上授予“完全控制权”:

  • 在IIS服务器上打开“注册表编辑器”(运行命令:regedit)。
  • 将光标放在左窗格中的根目录上。
  • 打开一个查找框并输入“ahadmin”并单击“查找”。
  • 注册表将在右侧窗格中找到一个键。右键单击父级 此密钥和打开属性框的文件夹
  • 转到“安全”标签并授予您的NT用户“完全控制”
  • 如果您无法授予“完全控制权”,请转到“所有者”标签 并添加您的NT用户或您所属的管理员组,然后单击“应用” 然后返回“安全”标签以授予您“完全控制权”

    您现在可以编辑dcom属性对象

    如果dcom porperties对象仍然锁定,请等待几分钟再试一次。

    之后,您只需按照here程序进行操作。

答案 3 :(得分:1)

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

答案 4 :(得分:1)

确保项目的文件夹未加密。 Visual Studio在使用加密文件夹时遇到问题。

我的用户文件夹已加密,在我将这些文件夹标记为未加密之前,项目无法打开。 VS没有提供有意义的错误,声明你应该从项目文件夹中删除加密,这是一个愚蠢的行为。

要删除加密,请右键单击项目文件夹,然后单击“高级”,然后取消选中“加密”复选框。将更改应用于文件夹本身以及所有嵌套文件夹和文件。

Disable encryption

答案 5 :(得分:0)

如果虚拟目录映射到共享文件夹。查看共享的权限,默认情况下在Windows 7 / w2k8下创建共享: 大家(阅读) 将共享的权限更改为: 每个人(FullControl)

这允许IIS通过共享执行所需的操作,因为它没有使用完整的物理路径。

相关问题