What's the difference between the WebConfigurationManager and the ConfigurationManager?

前端 未结 4 1663
臣服心动
臣服心动 2020-11-27 03:32

What\'s the difference between the WebConfigurationManager and the ConfigurationManager?

When should I use one over the other?

4条回答
  •  臣服心动
    2020-11-27 03:51

    Although WebConfigurationManager is located in the System.Web assembly the ConnectionStringSettingsCollection that it returns is located in System.Configuration.

    If you are getting the error

    Cannot apply indexing with [] to an expression of type 'System.Configuration.ConnectionStringSettingsCollection'

    while trying to access the array index...

    WebConfigurationManager.ConnectionStrings["Name"].ConnectionString
    

    make sure you have a reference to assembly System.Configuration

提交回复
热议问题