Tutorials » AspNet tutorials »

Web.config for Web applications

This chapter explains the web.config and various entries in the config file.

Web.config for Web applications

The web applications use the same concept, but they use a config file with the name web.config. There are couple of things to note in this case.

* web.config is created automatically by VS.NET when you create any web project.
* When you compile the web application, web.config is NOT renamed or copied to the BIN folder.
* web.config has several default entries in it to support web/IIS configuration & security.
* You can add the <appSettings> section in the web.config and add your key/value pairs in that section.
* You can have separate web.config files for each directory in your web application, in addition to the one in the root. For each web page, by default, system will look for a web.config in the same folder as the page and if not found, then looks in the parent folder.

You can store and retrieve key/value pairs in the web.config file just like the app.config files:

<?xml version="1.0" encoding= "utf-8" ?>



<add key="DatabasePath" value="c:\\projects\data\tutorials.mdb" />



To read key/value pairs from <appSettings> section, use the following code:

dim dbPath as string =

In addition to the <appSettings> section, another interesting entry in the web.config file is, <sessionState />. A typical sessionState section looks like this:

sqlConnectionString="data source=;user id=sa;password=" cookieless="false"

The above section allows you to set the session handling details for your web application. The mode="InProc" says the session will be stored in memory of the web server. The attributes stateConnectionString and sqlConnectionString are not used if the session is stored in memory. You will learn more about various session handling methods later.

The last attribute timeout="20" sets the session time out in minutes. If you want to change the default session timeout, change this value in the web.config file. You can learn more about session time out in this chapter.

Next Chapter: What is Global.asax file?
Previous Chapter: App.config for Windows applications
More Chapters: ASP.NET Tutorials
More Tutorials: Tutorial Index

Top Contributors
    Last 7 Daysmore...

    Awards & Gifts

    Online Members

    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India