如题,网上好多代码都是在winform程序下能实现,但是不能在asp.net下实现,老是报未知错误。搜索了好多代码都是不行。请做成功的高手指点迷经。

解决方案 »

  1.   

    我这里有些相关的文章,你好好找一下 .Net中如何操作IIS(源代码) 
    http://www.dezai.cn/index/Article_Show.asp?ArticleID=12605好像还有些,自已查一下吧
      

  2.   

    1.添加System.DirectoryServices
    2.using System.DirectoryServices;
    3.在代码事件中如下:
       protected void BT_submit_Click(object sender,EventArgs e)
        {
            string _server = "localhost";
            string _website = "1"; 
            string strPath = "IIS://" + _server + "/W3SVC/" + _website +"/ROOT";         dirroot = new DirectoryEntry(strPath);
            DirectoryEntry newVirDir = dirroot.Children.Add("MyNewSite3", "IIsWebVirtualDir");
            Response.Write(dirroot.Name);
            newVirDir.Invoke("AppCreate", true);
            newVirDir.CommitChanges();
            dirroot.CommitChanges();
            Response.Write(newVirDir.Name+"创建成功"+newVirDir.Path);
        }
      

  3.   

    这个我几年以前实现过(项目要求,但后来不要了,所以代码早不知丢哪去了:)),原理和winform没有什么区别,关键是asp.net应用程序是以aspnet这个用户执行的,它没有足够的权限操作IIS,所以你需要模拟一个管理员帐号才有权限实现这样的功能,关于模拟请看这个:http://support.microsoft.com/kb/306158/zh-cn
      

  4.   

    谢谢各位除了 webdiyer(陕北吴旗娃) 兄台的方法没有试过,其他我都试了,还是不行啊。
      

  5.   

    未知错误(0x80005000) 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Runtime.InteropServices.COMException: 未知错误(0x80005000)源错误: 
    行 165:
    行 166: DirectoryEntry root = new DirectoryEntry(strWeb);
    行 167: foreach(DirectoryEntry oEntry in root.Children)
    行 168: {
    行 169: if(oEntry.SchemaClassName == strSchema)
     
      

  6.   

    方法有两种:
    1,FSO
            Dim fso As New Scripting.FileSystemObject
            fso.CreateFolder(Server.MapPath(".") & "\user_info\" & Trim(tmpUsername))
            fso = Nothing2,IO.Directory.CreateDirectory
            system.IO.Directory.CreateDirectory(Server.MapPath(".") & "\user_info\" & Trim(tmpUsername))第二种方法需要设置权限,
    比如要在D盘上建目录,那么,在D盘上右键,然后把ASPNET用户组加入可读写权限中,就行了,记住,只能是在磁盘根目录设置
      

  7.   

    不知道楼主是怎么把权限设到最大了?这种问题见过很多,就模拟就可以了,看看这两个帖子:http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/c786756bc680384/a149df2863a82de3?lnk=st&q=create+virtual+directory+from+asp.net+page&rnum=8&hl=zh-CN#a149df2863a82de3http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/19450d1c83cb6e08/e53efb41982b880f?lnk=st&q=create+virtual+directory+from+asp.net+page&rnum=17&hl=zh-CN#e53efb41982b880f