2011-02-17 178 views
8

我使用Microsoft.Web.Administration.ServerManager類來管理Windows服務中的網站。applicationHost.config錯誤:由於IIS共享配置權限不足,無法寫入配置文件

我使用模擬在我的代碼,以管理員用戶,用戶有權修改權我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屬性對象是鎖定

Unhandled exception has occured in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately. FileName \?\UNC[MY PATH]\applicationHost.config Error: Cannot write configuration file due to insufficient permissions

我的設置是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

要解鎖你的dcom屬性對象,你只需要2個步驟來執行。

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

  • 轉到您的IIS服務器和瀏覽到文件夾 'C:\ WINDOWS \ SYSTEM32 \'
  • 查找「Ahadmin .dll文件「就可以了,然後右鍵單擊打開屬性框
  • 轉到‘安全’選項卡,並授予你的NT用戶‘’如果你不能夠授予您
  • ‘完全控制完全控制’,轉到這個」所有者'標籤 並添加您的NT用戶或您所屬的管理員組,然後點擊'應用' 而不是回到「安全」選項卡向您授予「完全控制」

第2步 - 授予你「完全控制」的註冊表項:

  • 在IIS服務器上打開「註冊表編輯器「(運行命令:regedit)。
  • 將光標放在左窗格的根目錄下。
  • 打開查找框並鍵入'ahadmin',然後單擊查找。
  • 註冊表將在右窗格中找到一個鍵。右鍵點擊此鍵的父 文件夾,打開屬性框
  • 轉到「安全」選項卡,如果你不能夠授予您「完全控制」授予您NT用戶「完全控制」
  • ,轉到「所有者」選項卡 並添加您的NT用戶或管理員組,然後單擊「應用」 然後返回「安全」選項卡授予您「完全控制」

    您現在可以編輯您的dcom屬性對象

    如果dcom porperties對象仍然鎖定,請等待幾分鐘,然後嘗試使用agai ñ。

    之後,你只需要按照程序here

0

確保兩個文件的安全設置和份額的安全設置允許扮演用戶修改文件。由於您正在使用UNC路徑訪問配置文件,因此您需要兩個級別的權限。

+0

沿着這些方向,檢查文件的有效權限(類似於右鍵單擊,屬性,安全性,高級權限和有效權限)。這應該給你一個什麼樣的用戶可以在文件系統級(NTFS)做了權威的排行榜。 – 2011-02-17 22:34:25

+0

Everyting是正確的,但還是不行 – 2011-02-21 19:28:09

0

如果虛擬目錄映射到共享文件夾。 所有人(讀取):windows下看共享的權限,默認7/W2K8股與創建。 更改共享的權限: 每個人(FullControl)

這使得IIS做什麼它需要通過份額,因爲它沒有使用完整物理路徑。

5

在我們的情況下,服務器磁盤已滿。我們添加了附加磁盤空間,問題解決了。

0

確保項目文件夾未加密。 Visual Studio在使用加密文件夾時遇到問題。

我有我的用戶文件夾加密和項目將無法打開,直到我將這些文件夾標記爲未加密。這是一個愚蠢的VS不提供一個有意義的錯誤,說明你應該從項目文件夾中刪除加密。

要刪除加密權利,請右鍵單擊項目文件夾,然後選擇高級,然後取消選中加密複選框。將更改應用於文件夾本身以及所有嵌套的文件夾和文件。

Disable encryption

2

我已經刪除了我的解決方案現有的ApplicationHost.config文件,並重新裝入的解決方案。解決方案本身創建了新的ApplicationHost.config文件。

它解決了我的問題。

相關問題