GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  DotNet
Go To First  |  Previous Question  |  Next Question 
 DotNet  |  Question 87 of 165    Print  
What is Web.config?
In classic ASP all Web site related information was stored in the metadata of IIS. This had the disadvantage that remote Web developers couldn't easily make Web-site configuration changes. For example, if you want to add a custom 404 error page, a setting needs to be made through the IIS admin tool, and you're Web host will likely charge you a flat fee to do this for you.
With ASP.NET, however, these settings are moved into an XML-formatted text file (Web.config) that resides in the Web site's root directory. Through Web.config you can specify settings like custom 404 error pages, authentication and authorization settings for the Web sitempilation options for the ASP.NET Web pages, if tracing should be enabled, etc.
The Web.config file is an XML-formatted file. At the root level is the <configuration> tag. Inside this tag you can add a number of other tags, the most common and useful one being the system.web tag, where you will specify most of the Web site configuration parameters. However, to specify application-wide settings you use the <appSettings> tag.
For example, if we wanted to add a database connection string parameter we could have a Web.config file like so:
<configuration>
<!-- application specific settings -->
<appSettings>
<add key="connString" value="connection string" />
</appSettings>
<system.web>
...
</system.web>
</configuration>
Now, in any of your ASP.NET Web pages in this Web site you can read the value of the connString parameter like so:
ConfigurationSettings.AppSettings("connString")
To avoid this complication you can "group" your application's settings into a unique tag in the Web.config file. That is, you can create a tag named: <MyAppSettings> in Web.config and then use the as we did earlier to add application-wide settings.
To add a custom tag to Web.config you need to first explicitly specify the new tag name in Web.config via the <configSections> tag, like so:
<configuration>
<configSections>
<section name="MyAppSettings"
type="System.Configuration.NameValueFileSectionHandler,
System, Version=1.0.3300.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
</configSections>
...
</configuration>
This <section ... /> tag indicates that we are going to be adding a custom tag named MyAppSettings. Now we can add a <MyAppSettings> tag to our Web.config file and add <add ... /> tags to add application-wide parameters, like so:
<configuration>
<configSections>
<section name="MyAppSettings"
type="System.Configuration.NameValueFileSectionHandler,
System, Version=1.0.3300.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
</configSections>
<MyAppSettings>
<add key="connString" value="connection string" />
</MyAppSettings>
...
</configuration>
To read this custom value from an ASP.NET Web page we use the following syntax:
ConfigurationSettings.GetConfig("MyAppSettings")("connString")



  
Total Answers and Comments: 1 Last Update: January 17, 2006   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
January 17, 2006 07:22:18   #1  
samiksc Member Since: October 2005   Contribution: 233    

RE: What is Web.config?

Web.config is the asp.net configuration file which stores configuration settings of the folder in which it resides and its subfolders. If a subfolder contains web.config then it overrides the settings of the parent web.config.

In this file you may keep settings for users and their access rights also changeable parameters like connection strings.

The advantage of keeping such information in web.config is that you don't need to recompile and redeploy the application if any of these settings have to be changed.

ASP.Net runtime automatically detects the changes and recalculates the web to effect changes.

This file is extensible. You can add your own settings to implement your configuration logic. This is possible since it is implemented as an XML file.


 
Is this answer useful? Yes | No

 Related Questions

A web farm is a multi-server scenario. So we may have a server in each state of US. If the load on one server is in excess then the other servers step in to bear the brunt. How they bear it is based 
Latest Answer : There is two or more than two server in webfarm method, and we also have a router in this technique, which is basically is used to route the a particular incoming  request .Where as in case of a webgarden we have a one server having more than one processor.There ...

ASP.NET implements authentication using authentication providers, which are code modules that verify credentials and implement other security functionality such as cookie generation. ASP.NET supports 
Latest Answer : One more authentication is called Client Certifiaction Authentication. ...

In classic ASP all Web site related information was stored in the metadata of IIS. This had the disadvantage that remote Web developers couldn't easily make Web-site configuration changes. For 
Latest Answer : Web.config is the asp.net configuration file which stores configuration settings of the folder in which it resides and its subfolders. If a subfolder contains web.config then it overrides the settings of the parent web.config.In this file you may keep ...

Machine configuration file: The machine.config file contains settings that apply to the entire computer. This file is located in the %runtime install path%Config directory. There is only one machine.config 
Latest Answer : Machine.config file resides in \config folder. It contains settings which apply to the entire computer. ...

Latest Answer : Configuration information for ASP.NET resources is contained in a collection of configuration files, each named Web.config. Each configuration file contains a nested hierarchy of XML tags and subtags with attributes that specify the configuration settings. ...
Read Answers (3) | Asked by : goldjoy


 Sponsored Links

 
Related Articles

The Interview Snafu

How to turn someone else&rsquo;s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won&rsquo;t get over the line without a polished, prof
 

Top 10 Application Security Vulnerabilities in Web.config Files - Part One

These days, the biggest threat to an network security comes from its public Web site and the Web-based applications found there. Unlike internal-only network services such as databases-which can be sealed off from the outside via firewalls-a public Web site is generally accessible to anyone who wan
 

Top 10 Application Security Vulnerabilities in Web.config Files - Part Two

Some of the most common and dangerous application security vulnerabilities that exist in ASP.NET Web-based applications come not from the C# or VB.NET code that make up its pages and service methods, but instead from the XML code that makes up its Web.config files. Incorrect configurations can open
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

HR Interview - HR Interview Mistakes You Will Want To Avoid

HR Interview Mistakes You Will Want To Avoid The job interview can be a stressful process This is especially true for those who are going after a competitive position Your nonverbal communication combined with the answers you give during the interview will determine if you are hired mosgoogle While
 

HR Interview - Behavioral HR Interviews

Behavioral HR Interviews As the name implies a behavioral interview is an interview that is held by a human resources department to determine if an applicant has the behaviors that are appropriate for a job The company must know how an applicant will behave in a certain situations mosgoogle The logi
 

HR Interview - How To Prepare For Your HR Interview

How To Prepare For Your HR Interview Before you begin thinking about how you are going to dress for the interview it is important to do your research first You should learn everything you can about the company you wish to work for When you have detailed information about your employer you will conve
 

HR Interview - Telephone Interview Etiquette

Telephone Interview Etiquette When you conduct a telephone interview for a job it is important to show the proper etiquette Not only is it important it is critical is you wish to be hired by the company There are a number of things you will want to do and other things should never be done mosgoogle
 

HR Interview - How To Succeed At HR Interviews

How To Succeed At HR Interviews There are a number of things you will need to do in order to make sure you pass the interview process Your appearance is something that you will want to pay close attention to Even if you feel that your appearance shouldn t be a factor in whether or not you re highere
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape