#1
看见网上其他人写的加了一句声明,就是多了一个新实例,
DirectoryEntry basic = new DirectoryEntry(stNewPath);
放在DirectoryEntry basic = new DirectoryEntry(stBasicPath, "administrator", "dfasasdasdfd", AuthenticationTypes.Secure ¦ AuthenticationTypes.None)之下。
结果报错如下:
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------
拒绝访问。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Runtime.InteropServices.COMException: 拒绝访问。
源错误:
行 36: if (basic == null) { throw new Exception("the basic " + stBasicPath + " is null,please try a later aglin"); }
行 37: DirectoryEntry en = new DirectoryEntry(stNewPath);
行 38: DirectoryEntry obj = basic.Children.Add(folderProperty.stName, "IIsWebVirtualDir");
行 39: obj.Properties["Path"][0] = folderProperty.stPath;
行 40: obj.Invoke("AppCreate", true);
源文件: d:\test_project\App_Code\System_IIS.cs 行: 38
堆栈跟踪:
[COMException (0x80070005): 拒绝访问。
]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +610
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
VirtualDirectory.create_VirtualDirectory(Properties folderProperty) in d:\test_project\App_Code\System_IIS.cs:38
Test.page_load() in d:\test_project\Test.aspx.cs:23
System.Web.Util.CalliHelper.ArglessFunctionCaller(IntPtr fp, Object o) +5
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +781887
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.42