2017-02-09 6 views
1

Windows Server 2012 R2のIISからWebサイトIDを取得しようとしています。 Idを取得してから、IISのWebサイト用のWebサイトポインタを追加します。私は、コードを実行する権限を与える場所と、Webサーバーを脆弱なままにしないで、同時にどこに権限を与えるかはわかりません。IISディレクトリサービス

Access is denied. 

Description: An unhandled exception occurred during the execution of the 
current web request. Please review the stack trace for more information 
about the error and where it originated in the code. 


Exception Details: System.Runtime.InteropServices.COMException: Access 
is denied. 


Source Error: 

22行目:DirectoryEntryをW3SVC =新しい のDirectoryEntry(String.Formatのここ

は、これがスローされるエラーです同上

string result = "-1"; 

    DirectoryEntry w3svc = new DirectoryEntry(string.Format("IIS://{0}/w3svc", "localhost")); 

    foreach (DirectoryEntry site in w3svc.Children) 
    { 
     if (site.Properties["ServerComment"] != null) 
     { 
      if (site.Properties["ServerComment"].Value != null) 
      { 
       if (string.Compare(site.Properties["ServerComment"].Value.ToString(), 

             "website.com", true) == 0) 
       { 
        result = site.Name; 
        break; 

       } 
      } 
     } 
    } 

    return result; 

を取得するための私のコードです( "IIS:// {0}/w3svc"、serverName)); 23行目: 24行目:foreachの(w3svc.Children中のDirectoryEntryサイト) 25行目:{ ライン26:(!site.Properties [ "ServerComment"] = null)の場合は

Source File: c:\inetpub\wwwroot\DNS_IIS\DNS.aspx.cs Line: 24 

Stack Trace: 


[COMException (0x80070005): Access is denied. 
] 
    System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) 
+597561 
    System.DirectoryServices.DirectoryEntry.Bind() +44 
    System.DirectoryServices.DirectoryEntry.get_IsContainer() +42 
    System.DirectoryServices.DirectoryEntries.GetEnumerator() +49 
    DNS.GetWebSiteId(String serverName, String websiteName) in c:\inetpub 
\wwwroot\DNS_IIS\DNS.aspx.cs:24 
    DNS.btnDNS_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot 
\DNS_IIS\DNS.aspx.cs:85 
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String 
eventArgument) +155 
    System.Web.UI.Page.ProcessRequestMain(Boolean 
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
+3804 

答えて

1

それ並べ替えるのは簡単なことでした。

私はApplicationPoolのアイデンティティをLocalSystemに変更しましたが、それは100%働いていました。