如题!
里面可能还涉及到权限配置的问题,请有此开发经验的高人指教!

解决方案 »

  1.   

    const String constIISWebSiteRoot = "IIS://localhost/W3SVC/1/ROOT";   DirectoryEntry root = new DirectoryEntry(constIISWebSiteRoot);
       DirectoryEntry entry = new DirectoryEntry(constIISWebSiteRoot + "/" + virtualDirName);   DirectoryEntry tbEntry = root.Children.Add(virtualDirName, "IIsWebVirtualDir");   //must be end with a '\' 
       tbEntry.Properties["Path"][0] = virtualDirPath;
       tbEntry.Invoke("AppCreate",true);
       tbEntry.Properties["AccessRead"][0] = true;
       tbEntry.Properties["ContentIndexed"][0] = false;
       tbEntry.Properties["DefaultDoc"][0] = "index.asp";
       tbEntry.Properties["AppFriendlyName"][0] = virtualDirName;
       tbEntry.Properties["AppIsolated"][0] = 2;
       tbEntry.Properties["AccessScript"][0] = true;   
       tbEntry.Properties["DontLog"][0] = true;   
       
       tbEntry.CommitChanges();
      

  2.   

    http://www.aspxboy.com/1252/default.aspx
      

  3.   

    或者  参考http://www.programfan.com/article/showarticle.asp?id=2455
      

  4.   

    楼上的代码我已经运行成功了:using System;
    using System.DirectoryServices;
    namespace BookTestClient
    {
       // Class to test the book database:
       class Test
       {
          // Print the title of the book.
          // Execution starts here.
          static void Main()
          {
    const String constIISWebSiteRoot = "IIS://localhost/W3SVC/1/ROOT";
    string virtualDirName = "ttttt";   DirectoryEntry root = new DirectoryEntry(constIISWebSiteRoot);
       DirectoryEntry entry = new DirectoryEntry(constIISWebSiteRoot + "/" + virtualDirName);   DirectoryEntry tbEntry = root.Children.Add(virtualDirName, "IIsWebVirtualDir");   //must be end with a '\' 
       tbEntry.Properties["Path"][0] = @"c:/inetpub/wwwroot/ttttt";
       tbEntry.Invoke("AppCreate",true);
       tbEntry.Properties["AccessRead"][0] = true;
       tbEntry.Properties["ContentIndexed"][0] = false;
       tbEntry.Properties["DefaultDoc"][0] = "index.asp";
       tbEntry.Properties["AppFriendlyName"][0] = virtualDirName;
       tbEntry.Properties["AppIsolated"][0] = 2;
       tbEntry.Properties["AccessScript"][0] = true;   
       tbEntry.Properties["DontLog"][0] = true;   
       
       tbEntry.CommitChanges();
          }   }
    }
    请问服务器要怎么配置才有权限运行
      

  5.   

    DirectoryEntry tbEntry = root.Children.Add(virtualDirName, "IIsWebVirtualDir");
    楼上iuhxq(小灰) 的那段代码,我执行到这一句的时候就报告下列错误:拒绝访问。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Runtime.InteropServices.COMException: 拒绝访问。源错误: