[開発ノート] -WebConfigurationManagerおよびConfigurationManager



Webconfigurationmanager



今日、私がプログラムを書いているときに、WebConfigurationManagerを使用してweb.configの構成情報を取得するいくつかのサンプルコードに出くわしました。 ConfigurationManagerは以前から使用されていたので、簡単に詳しく調べて簡単にまとめました。

MSDNの説明:



使用する WebConfigurationManager コンピューターとアプリケーションの情報にアクセスできます。

使用する WebConfigurationManager これは、Webアプリケーションに関連する構成ファイルを処理するための推奨される方法です。クライアントアプリケーションの場合は、 ConfigurationManager



それが次のように理解できるかどうかはわかりません:

1. Webアプリケーションの場合、使用することをお勧めします WebConfigurationManager ただし、この方法は、winformやWPFプログラムなどのクライアントアプリケーションには適していません。

二。 ConfigurationManager Webアプリケーションとクライアントアプリケーションの両方に適していますが、クライアントアプリケーションには適しています。



その他の仕上げ:

画像
 //For client applications, use ConfigurationManager. protected static string connectionString = ConfigurationManager.ConnectionStrings['ConnStr'].ToString() protected static string appconfigString = ConfigurationManager.AppSettings[''].ToString() //Using WebConfigurationManager is the preferred method of handling configuration files related to Web applications. protected static string webconnectionString = WebConfigurationManager.ConnectionStrings[''].ToString() protected static string webappconfigString = WebConfigurationManager.AppSettings[''].ToString() //Configuration node in Web.config: //ConnectionStrings // // // //AppSettings // // // //Write in and use System.Configuration.ConfigurationManager.AppSettings['name'] to retrieve the value. //Write in to retrieve the value using System.Configuration.ConfigurationManager.ConnectionStrings['name']. //Note: //System.Web.Configuration does not add a reference to the program by default, so it cannot be used directly.
画像


添付:

ソースを示してください。

この記事は、元のリンクであるCool Kids Blog Park Blogから転送されています:http://www.cnblogs.com/babycool/archive/2013/06/01/3112513.html転載が必要な場合は、原作者にご連絡ください