2011-11-11 44 views
1

我做了快速搜索,並得到了這個鏈接 From StackOverflow虛擬目錄屬性

我得到這個錯誤信息 「未知錯誤(0x80005000)」 當它擊中

bool canCreate = !(schema.Properties["Syntax"].Value.ToString().ToUpper() == "BOOLEAN"); 

我的要求是創建虛擬目錄並將AccessRead,IsolationMode,Scripts和Executables,ApplicationProtection設置爲中等。


得到它的工作,這裏是代碼:

注:我仍然無法得到它在Windows 7上運行,它會引發同樣的錯誤消息中包含引用System.InterOp ...目前我不在乎讓它在Windows 7上工作,我將它部署在Windows 2003上,它工作。

public void CreateVirtualDirectory(string virtualdirectory, string physicalpath) 
{ 
    try 
    { 
     ///check if path exists 
     if (!Directory.Exists(physicalpath)) 
     { 
      Log(string.Format(@"CreateVirtualDirectory; Path not found - {0}", physicalpath)); 
      return; 
     } 

     DirectoryEntry parent = new DirectoryEntry(string.Format("IIS://{0}/W3SVC/1/Root", Environment.MachineName)); 
     foreach (System.DirectoryServices.DirectoryEntry v in parent.Children) 
     { 
      if (v.Name == virtualdirectory) 
      { 
       try 
       { 
        parent.Invoke("Delete", new string[] { v.SchemaClassName, virtualdirectory }); 
       } 
       catch 
       { 
       } 
      } 
     } 
     DirectoryEntry newFolder = (DirectoryEntry)parent.Invoke("Create", "IIsWebVirtualDir", virtualdirectory); 
     newFolder.InvokeSet("Path", physicalpath); 
     newFolder.Invoke("AppCreate", false); 
     newFolder.InvokeSet("AppFriendlyName", virtualdirectory); 

     const int MEDIUM_POOL = 2; 

     newFolder.Properties["AccessRead"][0] = true; 
     newFolder.Properties["AccessExecute"][0] = true; 
     newFolder.Properties["AccessWrite"][0] = false; 
     newFolder.Properties["AccessScript"][0] = true; 
     newFolder.Properties["AuthNTLM"][0] = true; 
     newFolder.Properties["AppIsolated"].Clear(); 
     newFolder.Properties["AppIsolated"].Add(MEDIUM_POOL); 

     newFolder.CommitChanges(); 
    } 
    catch (Exception ex) 
    { 
     Log(string.Format(@"CreateVirtualDirectory '{0}' failed; {1}", virtualdirectory, ex.Message)); 
    } 
} 
+0

我的回答以下問題,爲什麼它不Win7上工作,並且做對2K3 – bryanmac

+0

你是正確的答案,我的壞我只是沒有之前得到它。在Windows 7的IIS 7上。我測試的Windows 7上的代碼應該在Windows 2003上工作。 – gangt

回答

1

您正在使用DirectoryEntry創建需要在IIS中安裝/配置IIS兼容模式的網站。如果您使用的是IIS7或更高版本,那麼這是IIS6目錄輸入接口的compat模式。

如果它沒有安裝,你會得到80005000.

如果你在IIS7或更高版本(Windows Server 2008或Vista和更高版本),較新的(非兼容模式)的方法是新的託管Microsoft.Web.Administration。

http://blogs.msdn.com/b/carlosag/archive/2006/04/17/microsoftwebadministration.aspx

+0

我在Windows 7上開發,但要在Windows 2003服務器上部署它。我不知道如果我在某些情況下修復它在Windows 7上,迄今爲止沒有發生,是否會在Windows 2003上有所不同? – gangt

+0

我得到它的工作。我更新了上面的代碼。 – gangt