public static void GetVirtualDirectoriesAssociatedWithApplication(Microsoft.Web.Administration.Application application) { VirtualDirectoryCollection directories = application.VirtualDirectories; foreach (VirtualDirectory directory in directories) { ConfigurationAttributeCollection attributes = directory.Attributes; foreach (ConfigurationAttribute attribute in attributes) { //put code here to work with each attribute } ConfigurationChildElementCollection childElements = directory.ChildElements; foreach (ConfigurationElement element in childElements) { //put code here to work with each ConfigurationElement } //get the directory.Path string path = directory.Path; //get the physical path string physicalPath = directory.PhysicalPath; } }
/// <summary> /// Gets the properties of an external system related to a specfied external system client. /// </summary> /// <param name="name">See icCore.dbo.ExternalSystem table</param> /// <param name="connection">Microsoft SQL Server connection</param> /// <returns></returns> public static ConfigurationAttributeCollection GetProperties(string name, IDbConnection connection) { Assert.IsNotNull(connection); var properties = new ConfigurationAttributeCollection { Name = name }; var dataSet = ExternalSystem_GetProperties(connection, name); var table = dataSet.Tables[0]; var row = table.Rows[0]; var loginame = row.GetReferenceField <string>(0); var currentUser = WindowsIdentity.GetCurrent().Name; DataProtectionScope scope; if (loginame == currentUser) { scope = DataProtectionScope.CurrentUser; } else { scope = DataProtectionScope.LocalMachine; } table = dataSet.Tables[1]; foreach (DataRow dataRow in table.Rows) { var propertyName = (string)dataRow[0]; var type = (ExternalSystemPropertyTypes)(byte)dataRow[1]; var value = dataRow[2]; var encrypted = (type & ExternalSystemPropertyTypes.Encrypted) != 0; if (encrypted) { if (value == DBNull.Value) { value = null; } else { var bytes = (byte[])value; value = ProtectedData.Unprotect(bytes, OptionalEntropy, scope); } } if (type == ExternalSystemPropertyTypes.String) { if (value == DBNull.Value) { value = null; } } properties.Add(propertyName, value, null); } return(properties); }
//设置IIS服务器ISAPI和CGI限制 private void SetIsapiRestriction() { Configuration config = manager.GetApplicationHostConfiguration(); ConfigurationSection isapiCgiRestrictionSection = config.GetSection("system.webServer/security/isapiCgiRestriction"); ConfigurationElementCollection isapiCgiRestrictionCollection = isapiCgiRestrictionSection.GetCollection(); foreach (ConfigurationElement element in isapiCgiRestrictionCollection) { ConfigurationAttributeCollection attributes = element.Attributes; if (attributes["path"].Value.ToString().ToLower().IndexOf(Model.FrameworkVersion.ToLower()) != -1) { attributes["allowed"].Value = true; } } }
private void View_Click(object sender, EventArgs e) { string name = VersionControlPath.GetFileName(this.item.ServerItem); var localFileName = Path.GetTempPath(); localFileName = Path.Combine(localFileName, name); this.item.DownloadFile(localFileName); ConfigurationNode node = Settings.CurrentType; ConfigurationAttributeCollection attributes = node.Attributes; string fileName; bool contains = attributes.TryGetAttributeValue("FileName", out fileName); var arguments = '"' + localFileName + '"'; var startInfo = new ProcessStartInfo(fileName, arguments); Process.Start(startInfo); }
public void GetConfigurrationAttribute() { ServerManager manager = new ServerManager(); Microsoft.Web.Administration.Configuration config = manager.GetApplicationHostConfiguration(); ConfigurationSection configSection = config.GetSection("system.applicationHost/serviceAutoStartProviders"); foreach (var item in configSection.GetCollection()) { if (item.Attributes["type"].Value.ToString() == "IISProcessScheduler.PreWarmUp, IISProcessScheduler") { } } ConfigurationAttributeCollection configAttributeCollection = configSection.Attributes; }
public static void TestServerManager() { ServerManager server = new ServerManager(); SiteCollection sites = server.Sites; foreach (Site site in sites) { ApplicationDefaults defaults = site.ApplicationDefaults; //get the name of the ApplicationPool under which the Site runs string appPoolName = defaults.ApplicationPoolName; ConfigurationAttributeCollection attributes = defaults.Attributes; foreach (ConfigurationAttribute configAttribute in attributes) { //put code here to work with each ConfigurationAttribute } ConfigurationAttributeCollection attributesCollection = site.Attributes; foreach (ConfigurationAttribute attribute in attributesCollection) { //put code here to work with each ConfigurationAttribute } //Get the Binding objects for this Site BindingCollection bindings = site.Bindings; foreach (Microsoft.Web.Administration.Binding binding in bindings) { //put code here to work with each Binding } //retrieve the State of the Site ObjectState siteState = site.State; //Get the list of all Applications for this Site ApplicationCollection applications = site.Applications; foreach (Microsoft.Web.Administration.Application application in applications) { //put code here to work with each Application } } }
internal ConfigurationElement(ConfigurationElement element, string name, ConfigurationElementSchema schema, ConfigurationElement parent, XElement entity, FileContext core) { Methods = new ConfigurationMethodCollection(); this.FileContext = parent?.FileContext ?? element?.FileContext ?? core; Section = parent?.Section; this.InnerEntity = entity ?? element?.InnerEntity; if (element == null) { if (name == null) { throw new ArgumentException("empty name"); } ElementTagName = name; Attributes = new ConfigurationAttributeCollection(this); ChildElements = new ConfigurationChildElementCollection(this); Collections = new List<ConfigurationElementCollection>(); RawAttributes = new Dictionary<string, string>(); ParentElement = parent; if (parent == null) { if (schema == null) { throw new ArgumentException(); } Schema = schema; IsLocallyStored = true; } else { IsLocallyStored = !parent.Section.IsLocked; var collection = parent.Schema.CollectionSchema; if (collection == null) { Schema = parent.Schema.ChildElementSchemas[name]; } else { Schema = parent.Schema.CollectionSchema.GetElementSchema(name) ?? parent.Schema.ChildElementSchemas[name]; } if (Schema == null) { throw new ArgumentException("empty schema"); } } ParseAttributes(); } else { IsLocallyStored = element.IsLocallyStored; ElementTagName = element.ElementTagName; Attributes = element.Attributes; ChildElements = element.ChildElements; Collections = element.Collections; RawAttributes = element.RawAttributes; Schema = element.Schema; ParentElement = parent ?? element.ParentElement; if (schema != null) { // TODO: here we ignore second schema //throw new ArgumentException(); } } }
public static void Write(XmlWriter xmlWriter, ConfigurationAttributeCollection attributes) { foreach (var attribute in attributes) { using (xmlWriter.WriteElement(ConfigurationElementName.Attribute)) { xmlWriter.WriteAttributeString("name", attribute.Name); var value = attribute.Value; if (value != null) { var type = value.GetType(); if (type != typeof(string)) { var typeName = TypeNameCollection.GetTypeName(type); xmlWriter.WriteAttributeString("type", typeName); } var typeCode = Type.GetTypeCode(type); string strValue; switch (typeCode) { case TypeCode.Object: if (type == typeof(TimeSpan)) { var timeSpan = (TimeSpan)value; strValue = timeSpan.ToString(); xmlWriter.WriteAttributeString("value", strValue); } else if (type.IsArray) { var array = (Array)value; for (var j = 0; j < array.Length; j++) { using (xmlWriter.WriteElement("a")) { value = array.GetValue(j); strValue = value.ToString(); xmlWriter.WriteAttributeString("value", strValue); } } } else { var xmlSerializer = new XmlSerializer(type); xmlSerializer.Serialize(xmlWriter, value); } break; default: strValue = value.ToString(); xmlWriter.WriteAttributeString("value", strValue); break; } } else { xmlWriter.WriteAttributeString("isNull", bool.TrueString); } } } }
public ConfigurationAttributeCollectionDebugger(ConfigurationAttributeCollection collection) { _collection = collection; }