26 July 2011

Interview questions .net: Configuration


Q. Explain how ASP.NET configuration files are organized.?

Answer. All configuration information resides between the <configuration> and </configuration> root XML tags. Configuration information between the tags is grouped into two main areas: the configuration section handler declaration area and the configuration section settings area.

Configuration section handler declarations appear at the top of the configuration file between <configSections> and </configSections> tags. Each declaration contained in a <section> tag specifies the name of a section that provides a specific set of configuration data and the name of the .NET Framework class that processes configuration data in that section.

The configuration section settings area follows the <configSections> area and contains the actual configuration settings. There is one configuration section for each declaration in the <configSections> area. Each configuration section contains subtags with attributes that contain the settings for that section.


contributed by:  Pinky Bhadran

Q.What are the benefits that ASP.NET configuration system provides?

Answer.  Configuration information is stored in XML-based text files. You can use any standard text editor or XML parser to create and edit ASP.NET configuration files.
Multiple configuration files, all named Web.config, can appear in multiple directories on an ASP.NET Web application server. Each Web.config file applies configuration settings to its own directory and all child directories below it. Configuration files in child directories can supply configuration information in addition to that inherited from parent directories, and the child directory configuration settings can override or modify settings defined in parent directories. The root configuration file named systemroot\Microsoft.NET\Framework\versionNumber\CONFIG\Machine.config provides ASP.NET configuration settings for the entire Web server.
At run time, ASP.NET uses the configuration information provided by the Web.config files in a hierarchical virtual directory structure to compute a collection of configuration settings for each unique URL resource. The resulting configuration settings are then cached for all subsequent requests to a resource. Note that inheritance is defined by the incoming request path (the URL), not the file system paths to the resources on disk (the physical paths).
ASP.NET detects changes to configuration files and automatically applies new configuration settings to Web resources affected by the changes. The server does not have to be rebooted for the changes to take effect. Hierarchical configuration settings are automatically recalculated and recached whenever a configuration file in the hierarchy is changed. The <processModel> section is an exception.
The ASP.NET configuration system is extensible. You can define new configuration parameters and write configuration section handlers to process them.
ASP.NET help protect configuration files from outside access by configuring Internet Information Services (IIS) to prevent direct browser access to configuration files. HTTP access error 403 (forbidden) is returned to any browser attempting to request a configuration file directly.


Contributed by  : Saravana Kumar

Q. How to change website configuration without restarting ASP.NET application?
   
Answer. Any change in Web.config file will cause ASP.NET application to restart. But, it is possible to create one or more external .config files which don't cause application restart. To connect external .config files with main Web.config, use configSource parameter.
Here is an example code snippet, used to read external configuration from three files:
<connectionStrings configSource="db.config"/>
   <appSettings configSource="app.config"/>

   <system.net>
       <mailSettings>
           <smtp configSource="mail.config"/>
       </mailSettings>
   </system.net>

So, in this example, we can change connection strings, application settings and mail settings. Application will not restart when any of these files change. Any external .config file should contain only section where is called. For example, db.config is called from <connectionStrings /> and should contain only connection strings, like this:

<connectionStrings>
     <clear />
     <add name="ConnStringName" connectionString="Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;" providerName="Syste.Data.SqlClient"/>
</connectionStrings>

index page asp.net interview questions click here

No comments:

Post a Comment