The Web.config is a configuration file used in .NET. This is an XML-based configuration file; we can develop a tool for modifying and editing this configuration file. If we change the contents of any web.config file then the change will be immediately reflected in the processing of any incoming requests to the web'server.
We can configure following setting using web.config file.
1)SessionStage 2)CustomErrors 3)Authorization 4)Authentication 5)Appsettings 6)SessionState 7)Trace 8)Globalization 9)Identity 10)MachineKey 11)ProcessModel 12)Compilation 13)Pages
Some of Commonly used configuration settings
Eg.
CustomErrors
If any unexpected error occurs this redirection will be used. The page will be redirected to "errorpage.aspx" page. The mode attribute takes three values On, Off or RemoteOnly. Remeteonly specifies that custom errors are shown only to remote clients.
< configuration> < system.web> < customErrors defaultRedirect="errorpage.aspx" mode="RemoteOnly"> < error statusCode="500" redirect="InternalErrorpage.htm"/> < /customErrors> < /system.web> < /configuration>
Pages
The buffer attribute specifies, whether resources are buffered or not. This takes three values On, Off and Readonly.
Using enableSessionState attribute we can enable the session state or disable the session. This takes two values, either TRUE or FALSE pageBaseType can be used to specify code-behind class that an .aspx page inherits. userControlBaseType specifies a code behind class that UserControls inherit.
< configuration> < system.web> < pages buffer="true" enableSessionState="true" autoEventWireup="true"> < /pages> < /system.web> < /configuration>
SessionState
We can set the timeout using timeout attribute. We can use cookies to store the session values using cookieless attribute. The mode attribute is used to specify where the session values will be stored. This can be specified in the mode attribute.
Supported values mode is Off, InProc, StateServer and SqlServer. InProc indicates that, session states are stored locally.
StateServer indicates that session state is stored on a remote server and sqlserver can be used to indicate that the session state is stored on an sql server
< configuration> < system.web> < sessionState mode="Inproc" cookieless="true" timeout="20"> < /sessionState> < /system.web> < /configuration>
Appsettings
We set a string variable ("strConnection") equal to ConfigurationSettings.AppSettings("ConnectionString"). We have now captured the connection string for use in our program.
< configuration> < appSettings> < add key="ConnectionString" value="server=localhost;database=Northwind;uid=sa;password=secret;" /> < /appSettings> < system.web> < customErrors mode="Off"/> < /system.web> < /configuration>
|
| Author: Praveen 30 May 2004 | Member Level: Silver Points : 0 |
Setting up of the web.config file is a very important and critical part of running an ASP.Net Web site. However, the article does not address all the attributes of the configuration file completely. Also, the flow is pretty ambiguous. If the treatment was not meant to be comprehensive, then the article should have taken only a few attributes into account and explained them in detail. Rather the article just breezes through a handful of disconnected parameters which don't quite help the reader get a fair idea of setting the configuration. I for one give a thumbs down.
|