当前位置:编程学习 > C#/ASP.NET >>

使用c#创建IIS站点时出错,提示拒绝访问 未处理COMException,只有35分了,会的朋友帮帮忙,谢谢!

以下是程序

  System.DirectoryServices.DirectoryEntry IISSchema;
            System.DirectoryServices.DirectoryEntry IISAdmin;
            System.DirectoryServices.DirectoryEntry VDir;
            bool IISUnderNT;
            string serverName = "localhost";

            //Install.Installer install = new Install.Installer();
            IISSchema = new System.DirectoryServices.DirectoryEntry("IIS://" + serverName + "/Schema/AppIsolated");
            if (IISSchema.Properties["Syntax"].Value.ToString().ToUpper() == "BOOLEAN")
                IISUnderNT = true;
            else
                IISUnderNT = false;
            IISSchema.Dispose();

            //         
            // Get the admin object          
            // 获得管理权限        
            //            
            IISAdmin = new System.DirectoryServices.DirectoryEntry("IIS://" + serverName + "/W3SVC/1/Root");
            VDir = IISAdmin;
            VDir.Properties["AppFriendlyName"][0] = "";    //应用程序名称 
            VDir.Properties["AccessRead"][0] = true; //设置读取权限 
            VDir.Properties["AccessExecute"][0] = false;
            VDir.Properties["AccessWrite"][0] = false;
            VDir.Properties["AccessScript"][0] = true; //执行权限[純腳本] 
            //VDir.Properties["AuthNTLM"][0] = chkAuth; 
            VDir.Properties["EnableDefaultDoc"][0] = true;
            VDir.Properties["EnableDirBrowsing"][0] = false;
            VDir.Properties["DefaultDoc"][0] = "Default.aspx,Index.aspx,Index.asp"; //设置默认文档,多值情况下中间用逗号分割 
            VDir.Properties["Path"][0] = @"D:\WORK\A3B2B";
            VDir.Properties["AuthFlags"][0] = 1;

            //        
            // NT doesn't support this property      
            // NT格式不支持这特性       
            //          
            if (!IISUnderNT)
            {
                VDir.Properties["AspEnableParentPaths"][0] = true;
            }

            //    
            // Set the changes        
            // 设置改变          
            //           
            VDir.CommitChanges();


            MessageBox.Show("创建成功!");



红色部分报错,提示信息:拒绝访问 未处理COMException --------------------编程问答-------------------- --------------------编程问答-------------------- VDir.Properties["AppFriendlyName"][0] = ""; 
这里开始报错,提示信息:拒绝访问 未处理COMException --------------------编程问答-------------------- --------------------编程问答-------------------- 有熟悉的么 --------------------编程问答-------------------- --------------------编程问答-------------------- DirectoryService好像是只要property不存在就会出异常的
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,