【问题标题】:How do I check "Allow IIS intrinsic properties" in a COM+ application programmatically?如何以编程方式在 COM+ 应用程序中检查“允许 IIS 内在属性”?
【发布时间】:2010-09-24 23:05:47
【问题描述】:

组件服务 -> 计算机 -> 我的电脑 -> COM+ 应用程序

打开一个 COM+ 应用程序对象。

打开组件。

右键单击一个类并选择属性。

在“高级”下有一个“允许 IIS 固有属性”复选框。

如何以编程方式选中此复选框?

我可以通过编程方式创建和删除 COM+ 应用程序,但 ComApplication 类似乎无法更改已创建应用程序中的设置。

【问题讨论】:

    标签: .net components com+


    【解决方案1】:

    我知道怎么做。

    显然我要获取COM+应用程序的集合,找到我想要的(按名称),然后获取应用程序中的组件集合,然后遍历集合并设置属性:

                //get collection of applications
            COMAdminCatalog catalog = new COMAdminCatalog();
    
            catalog.Connect("127.0.0.1");
    
            COMAdminCatalogCollection applications = (COMAdminCatalogCollection)catalog.GetCollection("Applications");
    
            applications.Populate(); //no idea why that is necessary, seems to be
    
            // appId for the application we are looking for
            object appId = new object();
    
            int count = applications.Count;
            ICatalogObject item;
    
            if (count == 0) return;
    
            //search collection for item with name we are looking for
            for (int i = 0; i < count; i++)
            {
    
                item = (ICatalogObject)applications.get_Item(i);
    
                if (applicationName == (string)item.get_Value("Name"))
                {
    
                    appId = item.Key;
    
                    Console.WriteLine("appId found for " + applicationName + ": " + appId.ToString());
    
                }
    
            }
    
            // get all components for the application
            COMAdminCatalogCollection components;
    
            components = (COMAdminCatalogCollection)applications.GetCollection("Components", appId);
            components.Populate(); // again, no idea why this is necessary
    
            // set the attribute in all components
    
            foreach (COMAdminCatalogObject component in components)
            {
    
                Console.WriteLine("Setting IISIntrinsics attribute in " + component.Name + ".");
                component.set_Value("IISIntrinsics", true);
                components.SaveChanges();
    
            }
    

    我认为这可以做得更好并且使用更少的演员表。但我不知道怎么做。

    这样就可以了。

    【讨论】:

    • 只是说几句,不知道具体的对象模型... 1. 初始化appId为null。 2. 找到应用后,使用“break”退出 for 循环。 3. 将 'if (appId != null)' 放在后续代码周围。 4. components.SaveChanges() 可能在foreach循环之外。
    【解决方案2】:

    我对这个特殊属性没有经验,但它似乎记录在 MSDN 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-09
      • 2019-10-01
      • 1970-01-01
      • 2022-11-05
      • 2015-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多