2014-09-05 69 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; 

而且解决了我的问题。

相关问题