visual valid name example comment comentarios c# asp.net configuration-files

c# - valid - crea tu propia configuración en xml



xml document c# (3)

Estoy en un proyecto de ASP.NET donde necesito dar varios parámetros al administrador que va a instalar el sitio web, como:

AllowUserToChangePanelLayout AllowUserToDeleteCompany

etc ...

Mi pregunta es, ¿será bueno agregar esto al archivo web.config, usar mi propia configSession o agregar como varibles de perfil? o debería crear un archivo XML para esto?

¿Qué haces y cuáles son los contras y los favoritos?

Originalmente pensé en web.config, pero luego me di cuenta de que debía estropear las configuraciones del sitio web y la configuración de mi propia aplicación web, y que debía crear un archivo diferente, lesí esta publicación y ahora estoy en este lugar ... debería hacer esto o aquello?


Usualmente uso la Configuración, disponible a través de las propiedades del proyecto - Configuración. Estos pueden ser editados y guardados en código, y yo escribo un formulario / página web para editarlos.

Si desea usar la configuración XML, hay un atributo llamado archivo que lee archivos externos. Puede tener un archivo web.config y un archivo someothername.config. El someothername.config tendría configuraciones como:

<appSettings> <add key="ConnString" value="my conn string" /> <add key="MaxUsers" value="50" /> </appSettings>

Y el web.config tendría

<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings file="ExternalWeb.config"> <add key="MyKey" value="MyValue" /> </appSettings> </configuration>

Ver DevX para el ejemplo que robé.


También puede poner sus configuraciones en un archivo de configuración. En su proyecto, abra Propiedades y vaya a Configuración que se ve como tal

Para acceder a los valores en su código, use Properties.Settings.YourSettingName;

Use Properties.Settings.Default.Reload(); para actualizar tu configuración durante el tiempo de ejecución


solo para que sepas que hice lo que el configurador recomienda, pero con un giro.

en lugar de preguntar todo el tiempo (que necesito) para

System.Configuration.ConfigurationManager.AppSettings["myKey"];

Acabo de crear una clase estática que extraería estos valores con lo que llamamos valores fuertemente tipados (para que no tenga que recordar todos los valores)

la clase mySettings

public static class mySettings { public enum SettingsType { UserPermitions, WebService, Alerts } public enum SectionType { AllowChangeLayout, AllowUserDelete, MaximumReturnsFromSearch, MaximumOnBatch, SendTo } public static String GetSettings(SettingsType type, SectionType section) { return ConfigurationManager.AppSettings[ String.Format("{0}_{1}", Enum.Parse(typeof(SettingsType), type.ToString()).ToString(), Enum.Parse(typeof(SectionType), section.ToString()).ToString()) ]; } }

la parte web.config appSettings

<configuration> <appSettings file="myApp.config"> <add key="UserPermitions_AllowChangeLayout" value="" /> <add key="UserPermitions_AllowUserDelete" value="" /> <add key="WebService_MaximumReturnsFromSearch" value="" /> <add key="Alerts_SendTo" value="" /> <add key="Alerts_MaximumOnBatch" value="" /> </appSettings> </configuration>

todo el archivo myApp.config

<?xml version="1.0" encoding="utf-8" ?> <!-- ### ### This file serves the propose of a quick configuration. ### Administrator can either change this values directly or use the ### Settings tab in the application. ### --> <appSettings> <!-- *** User Access Configuration *** --> <!-- Allow user to change the panels layout {1: Yes} {0: No} --> <add key="UserPermitions_AllowChangeLayout" value="1" /> <!-- Allow user to delete a company fro monitoring --> <add key="UserPermitions_AllowUserDelete" value="1" /> <!-- *** Web Service configuration *** --> <!-- Maximum responses from the search service --> <add key="WebService_MaximumReturnsFromSearch" value="10" /> <!-- *** Allerts configuration *** --> <!-- Send the alerts to the email writeen below --> <add key="Alerts_SendTo" value="[email protected]" /> <!-- Send an alert when user import more than the number bellow --> <add key="Alerts_MaximumOnBatch" value="10" /> </appSettings>

Entonces, ahora llamo así:

p.value = mySettings.GetSettings( mySettings.SettingsType.WebService, mySettings.SectionType.MaximumReturnsFromSearch);

Espero que ayude a alguien con el mismo problema :)