2014-09-05 47 views
0

我想爲我的VirtualDirectory設置憑據。我以前創建的用戶和我所做的是:如何設置VirtualDirectory憑據

 DirectoryEntry site = new DirectoryEntry"IIS://localhost/W3SVC/1/Root"); 
     string className = site.SchemaClassName.ToString(); 
     if ((className.EndsWith("Server")) || (className.EndsWith("VirtualDir"))) 
     { 
      DirectoryEntries vdirs = site.Children; 
      DirectoryEntry existingDirectoryEntry = vdirs.OfType<DirectoryEntry>().SingleOrDefault(d => d.Name == name); 
      if (existingDirectoryEntry != null) 
       throw new Exception("The virtual directory you want to create already exists"); 

      DirectoryEntry newVDir = vdirs.Add(name, (className.Replace("Service", "VirtualDir"))); 
      newVDir.Username = username; 
      newVDir.Password = password; 
      newVDir.Properties["Path"][0] = path; 
      newVDir.Properties["AccessScript"][0] = true; 
      if (authFlags.HasValue) 
       newVDir.Properties["AuthFlags"].Value = authFlags.Value; 

      newVDir.CommitChanges(); 
     } 

未設置用戶名和密碼目錄已正確創建。當我設置用戶名和密碼時,我收到系統找不到指定路徑的消息,但存在路徑。也許我應該改變某種身份驗證類型?

回答

0

我終於找到了解決方案。在這種情況下,用戶名和密碼應通過屬性設置,而不是直接在對象中設置:

newVDir.Properties["UNCUserName"][0] = username; 
newVDir.Properties["UNCPassword"][0] = password; 

而且解決了我的問題。

相關問題