INTERVIEW QUESTIONS
MICROSOFT
DOTNET
DETAILS
Question: What is Web.config?
Answer: 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")
|
Question:
What is Web.config?
Answer:
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") Source: CoolInterview.com
Web.con fig file is a collection of settings. like database. session state. error handling security. if u want to do any change we can perform here so it reflect to entire project.
Example: we develop a project for a company, that company shifted a new place so address is changed. In this time what we do simply changes in web.config file. Source: CoolInterview.com
Answered by: Srikar | Date: 11/16/2009
| Contact Srikar
Web.config file, as it sounds like is a configuration file for the Asp .net web application. An Asp .net application has one web.config file which keeps the configurations required for the corresponding application. Web.config file is written in XML with specific tags having specific meanings Source: CoolInterview.com
Answered by: sreenivaas varma bolisetty | Date: 1/5/2010
| Contact sreenivaas varma bolisetty
Web.config file is a collection of settings. like database. session state. connection string relted info if u want to do any change we can perform here so it reflect to entire project.
Example: we develop a project for a company, that company shifted a new place where we have a different p.c.that time what we do simply change the connectin string reside in web,cofig file.. Source: CoolInterview.com
Answered by: himanshu | Date: 5/24/2010
| Contact himanshu
•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 systemrootMicrosoft.NETFrameworkversionNumberCONFIGMachine.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. Source: CoolInterview.com
Answered by: Rajesh Puhazhendhi | Date: 7/9/2010
| Contact Rajesh Puhazhendhi
?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 Source: CoolInterview.com
Answered by: venkataramana | Date: 7/22/2010
| Contact venkataramana
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|