asp.net 动态创建虚拟目录问题 如题,网上好多代码都是在winform程序下能实现,但是不能在asp.net下实现,老是报未知错误。搜索了好多代码都是不行。请做成功的高手指点迷经。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我这里有些相关的文章,你好好找一下 .Net中如何操作IIS(源代码) http://www.dezai.cn/index/Article_Show.asp?ArticleID=12605好像还有些,自已查一下吧 1.添加System.DirectoryServices2.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); } 这个我几年以前实现过(项目要求,但后来不要了,所以代码早不知丢哪去了:)),原理和winform没有什么区别,关键是asp.net应用程序是以aspnet这个用户执行的,它没有足够的权限操作IIS,所以你需要模拟一个管理员帐号才有权限实现这样的功能,关于模拟请看这个:http://support.microsoft.com/kb/306158/zh-cn 谢谢各位除了 webdiyer(陕北吴旗娃) 兄台的方法没有试过,其他我都试了,还是不行啊。 未知错误(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) 方法有两种: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用户组加入可读写权限中,就行了,记住,只能是在磁盘根目录设置 不知道楼主是怎么把权限设到最大了?这种问题见过很多,就模拟就可以了,看看这两个帖子: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 GridView如何取数据行里的值 动态增加textbox 请教如何将虚拟主机数据库备份到本地数据库,多谢!!! 如何下载文件夹内的word文件,文件名称存放在数据库中 关于弹出提示框 ajax发布到2008 server失效问题!急求解 从Excel表格导出数据到SQL Server。 如何用xmlhttp获取远程网页的内容呢? 用asp.net开发网页,有什么好的代码调试工具么?请推荐一下 在线等:请问在Asp.net中怎么实现建立一数据表,该数据表的名字应为文本框传来的参数。 高手帮帮忙,怎么回事啊? 关于查询的问题
http://www.dezai.cn/index/Article_Show.asp?ArticleID=12605好像还有些,自已查一下吧
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);
}
说明: 执行当前 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)
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用户组加入可读写权限中,就行了,记住,只能是在磁盘根目录设置