主题:[讨论]请教关于用.NET创建虚拟目录的问题
我的代码:
string virtualDirName =this.TextBox1.Text;
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");
tbEntry.Properties["Path"][0] =@"c:\\inetpub\\wwwroot\\" + virtualDirName +"\\";
tbEntry.Invoke("AppCreate",true);
tbEntry.Properties["AccessRead"][0] = true;
tbEntry.Properties["ContentIndexed"][0] = false;
tbEntry.Properties["DefaultDoc"][0] = "iisstart.asp";
tbEntry.Properties["AppFriendlyName"][0] = virtualDirName;
tbEntry.Properties["AppIsolated"][0] = 2;
tbEntry.Properties["AccessScript"][0] = true;
tbEntry.Properties["DontLog"][0] = true;
tbEntry.CommitChanges();
运行时报的错:
拒绝访问。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Runtime.InteropServices.COMException: 拒绝访问。
谁帮我解决下啊`~谢谢了!!
string virtualDirName =this.TextBox1.Text;
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");
tbEntry.Properties["Path"][0] =@"c:\\inetpub\\wwwroot\\" + virtualDirName +"\\";
tbEntry.Invoke("AppCreate",true);
tbEntry.Properties["AccessRead"][0] = true;
tbEntry.Properties["ContentIndexed"][0] = false;
tbEntry.Properties["DefaultDoc"][0] = "iisstart.asp";
tbEntry.Properties["AppFriendlyName"][0] = virtualDirName;
tbEntry.Properties["AppIsolated"][0] = 2;
tbEntry.Properties["AccessScript"][0] = true;
tbEntry.Properties["DontLog"][0] = true;
tbEntry.CommitChanges();
运行时报的错:
拒绝访问。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Runtime.InteropServices.COMException: 拒绝访问。
谁帮我解决下啊`~谢谢了!!