Assembly : System.Web (dans system.web.dll)
SyntaxePublic Shared Function OpenWebConfiguration ( _ path As String _ ) As Configuration
Dim path As String Dim returnValue As Configuration returnValue = WebConfigurationManager.OpenWebConfiguration(path)
public static Configuration OpenWebConfiguration ( string path )
public: static Configuration^ OpenWebConfiguration ( String^ path )
public static Configuration OpenWebConfiguration ( String path )
public static function OpenWebConfiguration ( path : String ) : Configuration
Paramètres
- path
Chemin d'accès virtuel du fichier de configuration. Si référence Null (Nothing en Visual Basic), le fichier racine Web.config est ouvert.
Valeur de retour
Objet Configuration.
NotesPour obtenir le Configuration d'une ressource, votre code doit disposer de privilèges de lecture sur l'ensemble des fichiers de configuration dont il hérite des paramètres. Pour mettre à jour un fichier de configuration, votre code doit avoir, en outre, des privilèges d'écriture à la fois pour le fichier de configuration et pour le répertoire dans lequel il se trouve.
| Topic | Location |
|---|---|
| Comment : accéder par programme aux paramètres de configuration ASP.NET | Configuration d'applications Web ASP.NET |
| Comment : afficher des paramètres de configuration locaux et hérités par programme | Configuration d'applications Web ASP.NET |
| Comment : lire les paramètres de l'application dans le fichier Web.config | Configuration d'applications Web ASP.NET |
| Comment : verrouiller des paramètres de configuration ASP.NET | Configuration d'applications Web ASP.NET |
ExempleL'exemple de code suivant montre comment accéder aux informations de configuration avec la méthode OpenWebConfiguration.
' Show how to use OpenWebConfiguration(string). ' It gets he appSettings section of a Web application ' runnig on the local server. Shared Sub OpenWebConfiguration1() ' Get the configuration object for a Web application ' running on the local server. Dim config As System.Configuration.Configuration = _ WebConfigurationManager.OpenWebConfiguration("/configTest") ' Get the appSettings. Dim appSettings As KeyValueConfigurationCollection = _ config.AppSettings.Settings ' Loop through the collection and ' display the appSettings key, value pairs. Console.WriteLine("[appSettings for app at: {0}]", "/configTest") Dim key As String For Each key In appSettings.AllKeys Console.WriteLine("Name: {0} Value: {1}", _ key, appSettings(key).Value) Next key Console.WriteLine() End Sub 'OpenWebConfiguration1
// Show how to use OpenWebConfiguration(string). // It gets he appSettings section of a Web application // runnig on the local server. static void OpenWebConfiguration1() { // Get the configuration object for a Web application // running on the local server. System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("/configTest") as System.Configuration.Configuration; // Get the appSettings. KeyValueConfigurationCollection appSettings = config.AppSettings.Settings; // Loop through the collection and // display the appSettings key, value pairs. Console.WriteLine("[appSettings for app at: {0}]", "/configTest"); foreach (string key in appSettings.AllKeys) { Console.WriteLine("Name: {0} Value: {1}", key, appSettings[key].Value); } Console.WriteLine(); }
Plates-formesWindows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition
Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ