alt
Advertisement

Online Training
Career Series
Exforsys
Exforsys arrow Tutorials arrow ASP.NET arrow Configuring and Deploying ASP.NET Applications
Site Search
Sponsored Links



Configuring and Deploying ASP.NET Applications
Article Index
Configuring and Deploying ASP.NET Applications
Page 2
Page 3
Asp.net applications can be easily configured by using web.config files. You can store number of things in the configuration file. Let's see some important stuff that can be stored in this file.

Database Connections

The most important thing to store in the web.config file is the database connection string. The reason of storing connection string in the web.config file makes sense since if later we ever want to change the location of our database we just have to change the connection string in the web.config file and thats it. This will certainly save us a lot of alteration in different files where we used the old connection.

Lets see a small example of the connection string which is stored in the web.config file.

 

< configuration >

< appSettings >

< add key="ConnectionString " value="server=localhost;uid=sa;pwd=;database=DBPerson" / >

< / appSettings >

< / configuration >


As you can see its really simple to store the connection string in the web.config file. The connection string is referenced by a key which in this case is "ConnectionString". The value attribute of the configuration file denotes the information about the database. Here we can see that if has database name, userid and password. You can define more options if you want.

There is a very good website that deals with all sorts of connection strings. Its called www.connectionstrings.com , in the website you will find the connection strings of all sorts of databases.

lets see how we access the connection string from our Asp.net web application.

using System.Configuration;

string connectionString = (string )ConfigurationSettings.AppSettings["ConnectionString"];

As you see its very simple to get the connection String out from the web.config and than use it in your application.

Session States

Session in Asp.net web application is very important. As we know that HTTP is a stateless protocol and we needs session to keep the state alive. Asp.net stores the sessions in different ways. By default the session is stored in the asp.net process. You can always configure the application so that the session will be stored in one of the following ways.

1) Session State Service

There are two main advantages of using the State Service. First the state service is not running in the same process as the asp.net application. So even if the asp.net application crashes the sessions will not be destroyed. Any advantage is sharing the state information across a Web garden (Multiple processors for the same computer).

Lets see a small example of the Session State Service.


/>

The attributes are self explanatory but I will go over them.

mode: This can be StateServer or SqlServer. Since we are using StateServer we set the mode to StateServer.

stateConnectionString: connectionString that is used to locate the State Service.

sqlConnectionString: The connection String of the sql server database.

cookieless: Cookieless equal to false means that we will be using cookies to store the session on the client side.



 
< Prev   Next >
Sponsored Links
© 2008 Exforsys.com
Joomla! is Free Software released under the GNU/GPL License.
Page copy protected against web site content infringement by Copyscape