Programming in almost language

This is the site where you may share your knowledge and experience to eachother..

  • Categories

  • LinkedIn

  • Tweet Me

  • My footsteps

  • Advertisements

Archive for the ‘WebConfig and Global.asax’ Category

Read Configuration Settings of Web.config using Javascript

Posted by Praveen Kumar on April 5, 2008

Web.config is a XML file containing the configuration settings of our application. Amongst its other uses, the file is extremely handy when it comes to changing configuration settings of an application, even when the application is live. You can define your own specific application settings, such as a database connection string using the <appSettings> tag and read and write values to the file programmatically. In this article, we see how to read the configuration settings in the web.config using ‘JavaScript’.

ASP.NET provides the Web Site Administration Tool to view and manage the configuration settings for your ASP.NET website. These configuration settings are stored in an xml file called web.config.

“web.config is an application configuration file used to define configuration settings such as connecting strings, authentication, authorization etc., for an ASP.NET application

In this short article, I will see how we can retrieve the values from the  <appSettings> and <connectionStrings> section in the web.config using JavaScript. So let us get started.

Step 1: Create a new ASP.NET website. Add a button control to the Default.aspx.

Step 2: Right click the project > Add New Item > Web Configuration File
Add the following sample entries in the file between the <configuration> tag as shown below:






<addname=MyConnStringconnectionString=Data Source=(local);Initial Catalog=Northwind;Integrated Security=True;/>


Step 3: We will now read these entries using JavaScript. To do so, add the following script in the <head> tag of your Default.aspx page as shown below:
<head runat=”server”>
<title>Read Config Entries Using Javascript</title>
<script type=”text/javascript”>
function ReadConfigSettings()
var conn = ‘<%=ConfigurationManager.ConnectionStrings[“MyConnString”].ConnectionString %>’
var v1 = ‘<%=ConfigurationManager.AppSettings[“var1”].ToString() %>’
Step 4: Call this function on a button click and display the values of the configuration settings
<asp:Button ID=”Button1″ runat=”server” Text=”Button”OnClientClick=”ReadConfigSettings()” /></div>
That’s it. Run the application and click the button. The values of the configuration settings in the web.config will be displayed in the alert boxes.

I hope you liked this short article and I thank you for viewing it. If you liked the article,

then please comment it or give me suggestion to make more effective.


Posted in WebConfig and Global.asax | 24 Comments »

ASP.NET Configuration Web.Config Files Elements

Posted by Praveen Kumar on April 5, 2008

The elements in this schema tell us how our ASP.NET web application is going to behave.

Note: Default values are for your server can be found in your Machine.Config file that is located in ..\Microsfot.Net\Framework\version#\config\Machine.config

The root element of your configuration file is <configuration>:


The following is a overview of all the XMl files Elements (Schema) in your Web.Config file:


Configuration files as you know are in XML format. The actual schema for all three of Machine Configuration files, Application configuration and security configuration files is broken down to the following elements:

The child elements are:

  1. Startup

    This setting specifies what version of the CLR your application will run

    Elements include: requiredRuntime, supportedRuntime

  2. Runtime

    The runtime settings specificy how the CLR will handle garbage collection along with the version of the assembly to use

    Elements include: assemblybinding, assemblyIdentity, bindingRedirect, codeBase, dependantAssembly, devleopmentMode, gcConcurrent, probling, publisherPolicy, qualifyAssembly, runtime

  3. Remoting

    This section allows you to put custom settings in remoting application configuration files

    Elements include: system.runtime.remoting, application, lifetime, channels, serverProviders, formatter, client, wellknown, activiated, service, interopXmlType, preload, channelSinkProviders, provider, debug and customErrors

  4. Network Settings

    Determines how the .NET framework will connect to the internet.

    Elements include: authenticationModules, connectionModules, defaultProxy,, webRequestModules

  5. Cryptography

    Specifies how to map algorithm names to classes that implement the cryptography algorithms.

    Elements include: cryptoClasses, cryptoClass, cryptoghraphySettings, mscorlib, nameEntry, oidEntry, oidMap

  6. Configuration Sections

    Elements for custom settings in configuration files

    Elements include: add, appSettings, clear, configSections, remove, section, sectionGroup

  7. Trace and Debug Settings

    Tracing and Debugging settings that specify how trace listerners will collection and route messages and also at what levels the tracing listerners are set

    Elements include: add, assert, listeners, remove, switches, system.diagnostics, trace

  8. ASP.NET Settings

    Contains elements that control how your ASP.NET Web application will react. Please refer to your machine.config for default settings.
    Elements include: system.web, add, allow, assemblies, authentication, authorization, broswerCaps, case, clear, clientTarget, compilation, compiler, credentials, customErrors, deny, error, filter, forms, globalization, httpHandlers, httpModules, httpRuntime, identity, location, machineKey, pages, passport, processModel, protocols, remove, result, securityPolicy, sessionState, soapExtensionImporterTypes, soapExtensionReflectorTypes, soapExtensionTypes, trace, trust, trustLevel, use, user, webServices, WsdlHepGenerator.

Posted in WebConfig and Global.asax | Leave a Comment »