SIGN UP MEMBER LOGIN:    
ARTICLE

Web.config file configures fundamental settings

Posted by Nipun Tomar Articles | ASP.NET Programming September 10, 2008
Every web application in ASP.NET includes a web.config file that configures fundamental settings from error message to security.
Reader Level:
Download Files:
 

Every web application in ASP.NET includes a web.config file that configures fundamental settings from error message to security.
It uses a predefined XML format. THe entire content of the file is nested in a root<configuration> element.The elementary structure of the Web.config
is:-

<?xml version="1.0" ?>
<
configuration>
<
configSections>...</configSections>
<
appSettings>...</appSettings>
<
connectionStrings>...</connectionStrings>
<
system.web>...</system.web>
<
system.codedom>...</system.codedom>
<
system.webServer>...</system.webServer>
</
configuration>

remember it is case sensitive, like all XML documents.
Now it has <appSettings> section allows us to add our own miscellaneous pieces of information.
The <connectionStrings> section allows us to define the connection information for accessing a database. Finally, the <system.web> section holds every ASP.NET setting we’ll need to configure.
Inside the <system.web> element are separate elements for each aspect of website
configuration. we can include as few or as many of these as we want.Here coms the concept of nested configuration.
It uses multilayered configuration.
Storing custom setting in the web.config file
using neste <appSetings> in the root <configuraion>element
here is the basic :-

<?xml version="1.0" ?>
<
configuration>
...
<appSettings>
<!--
Custom application settings go here. -->
</
appSettings>
...
<system.web>
<!--
ASP.NET Configuration sections go here. -->
</
system.web>
...
</configuration>

Path is defined for storing important information as such:-

<appSettings>
<
add key="DataFilePath" value="e:\NetworkShare\Documents\WebApp\Shared" />
</
appSettings>
Down is the simple test page for quering and displaying result:-

using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
public partial class ShowSettings : System.Web.UI.Page
{
protected void Page_Load()
{
lblTest.Text =
"This app will look for data in the directory:<br /><b>";
lblTest.Text +=
WebConfigurationManager.AppSettings["DataFilePath"];
lblTest.Text +=
"</b>";
}
}

Login to add your contents and source code to this article
share this article :
post comment
 

Though the article is very old.. but i found it useful.. Thank You

Posted by Suresh Paldia Nov 10, 2010
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor