Microsoft.Web.Administration.ConfigurationElement.GetAttribute C# (CSharp) Method

GetAttribute() public method

public GetAttribute ( string attributeName ) : ConfigurationAttribute
attributeName string
return ConfigurationAttribute
        public ConfigurationAttribute GetAttribute(string attributeName)
        {
            if (this.Schema != null && !this.Schema.AllowUnrecognizedAttributes
                && this.Schema.AttributeSchemas.All(schema => schema.Name != attributeName))
            {
                throw new COMException(
                    string.Format(
                        "Filename: \\\\?\\{0}\r\nLine number: {1}\r\nError: Unrecognized attribute '{2}'\r\n\r\n",
                        this.FileContext.FileName,
                        (this.Entity as IXmlLineInfo).LineNumber,
                        attributeName));
            }

            return Attributes[attributeName];
        }

Usage Example

Example #1
0
        public static void Install(UdpInstallerOptions options)
        {
            if (options.ListenerAdapterChecked)
            {
                WebAdmin.ServerManager                  sm = new WebAdmin.ServerManager();
                WebAdmin.Configuration                  wasConfiguration           = sm.GetApplicationHostConfiguration();
                WebAdmin.ConfigurationSection           section                    = wasConfiguration.GetSection(ListenerAdapterPath);
                WebAdmin.ConfigurationElementCollection listenerAdaptersCollection = section.GetCollection();
                WebAdmin.ConfigurationElement           element                    = listenerAdaptersCollection.CreateElement();
                element.GetAttribute("name").Value     = UdpConstants.Scheme;
                element.GetAttribute("identity").Value = WindowsIdentity.GetCurrent().User.Value;
                listenerAdaptersCollection.Add(element);
                sm.CommitChanges();
                wasConfiguration = null;
                sm = null;
            }

            if (options.ProtocolHandlerChecked)
            {
                Configuration    rootWebConfig = GetRootWebConfiguration();
                ProtocolsSection section       = (ProtocolsSection)rootWebConfig.GetSection(ProtocolsPath);
                ProtocolElement  element       = new ProtocolElement(UdpConstants.Scheme);

                element.ProcessHandlerType   = typeof(UdpProcessProtocolHandler).AssemblyQualifiedName;
                element.AppDomainHandlerType = typeof(UdpAppDomainProtocolHandler).AssemblyQualifiedName;
                element.Validate             = false;

                section.Protocols.Add(element);
                rootWebConfig.Save();
            }
        }
All Usage Examples Of Microsoft.Web.Administration.ConfigurationElement::GetAttribute