views:

93

answers:

1

hi

We can retrieve configuration sections from web.config in the following two ways:

    Configuration config = WebConfigurationManager.OpenWebConfiguration("/");

    AuthenticationSection authSection = (AuthenticationSection)
           config.GetSection(@"system.web/authentication");

OR

AuthenticationSection authSection = (AuthenticationSection)           
       WebConfigurationManager.GetSection(@"system.web/authentication");

How are the two approaches different ( besides the fact that in the first example we retrieved a configuration section via Configuration object, which represents a configuration file )?

thanx

+2  A: 

You didn't use 2 different approaches. If you look carefully your statements are almost identical. The only minor difference is that in the second one the Open statement is implied and automated through the object. They both do the same thing the same exact way.

Joel Etherton
I thought that perhaps there is a difference from which web.config file the authentication section is retrieved.In the first case it is retrieved from root web.config, but in the second case it may get retrieved from some other app's web.config file(if it exists)
carewithl
They both open the default web.config for the current application (based on existing folder), start at the root and search for system.web/authentication.
Joel Etherton
thanx for helping me
carewithl