关于ASP.NET操作IIS中的虚拟目录

[复制链接]
查看11 | 回复3 | 2009-7-30 21:38:44 | 显示全部楼层 |阅读模式
//假如虚拟目录名为"Webtest",先在项目中引用
//System.DirectoryServices.dll,再
using System.DirectoryServices;
protected System.DirectoryServices.DirectoryEntry dirroot;
1、添加新的虚拟目录
DirectoryEntry newVirDir = dirroot.Children.Add("Webtest","IIsWebVirtualDir");
newVirDir.Invoke("AppCreate",true);
newVirDir.CommitChanges();
dirroot.CommitChanges();
2、更改虚拟目录属性
//虚拟目录的属性较常用的有:AccessRead,AccessWrite,AccessExecute,AccessScript,DefaultDoc,EnableDefaultDoc,Path等
DirectoryEntry Dirport = dirroot.Children.Find("Webtest","IIsVirtualDir");
Dirport .Properties["AccessRead"][0] = true;
3、删除虚拟目录
DirectoryEntry Dirport = dirroot.Children.Find("Webtest","IIsVirtualDir");
Dirport.Invoke("AppDelete",true);
dirroot.CommitChanges();
或者:
object[] part = new object[2];
part[0] = "IIsWebVirtualDir";
part[1] = "Webtest";
dirroot.Invoke("Delete",part);
dirroot.CommitChanges();
按照这样写程序,得到结果说
源错误:
行 24:
行 25:
行 26:
DirectoryEntry newVirDir = dirroot.Children.Add("Webtest", "IIsVirtualDir");
行 27:
行 28:
newVirDir.Invoke("AppCreate", true);
源文件: C:\C#\WebApplication1\WebApplication1\Default.aspx.cs
行: 26
堆栈跟踪:
[COMException (0x80070003): 系统找不到指定的路径。
]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +451
System.DirectoryServices.DirectoryEntry.Bind() +36
System.DirectoryServices.DirectoryEntry.get_IsContainer() +31
System.DirectoryServices.DirectoryEntries.CheckIsContainer() +13
System.DirectoryServices.DirectoryEntries.Add(String name, String schemaClassName) +13
WebApplication1._Default.Page_Load(Object sender, EventArgs e) in C:\C#\WebApplication1\WebApplication1\Default.aspx.cs:26
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436

回复

使用道具 举报

千问 | 2009-7-30 21:38:44 | 显示全部楼层
是不是权限有问题....
回复

使用道具 举报

千问 | 2009-7-30 21:38:44 | 显示全部楼层
关于asp.net路径和目录http://hi.baidu.com/lonetraveller/blog/item/b3e855b1f688ee5d092302b9.html...
回复

使用道具 举报

千问 | 2009-7-30 21:38:44 | 显示全部楼层
版本号选对了么?...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行