ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.
You can create a Web.config file by using a text editor such as Notepad. You must create a text file that is named Web.config in the root directory of your ASP.NET application. The Web.config file must be a well-formed XML document and must have a format similar to the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\Machine.config file.
The Web.config file must contain only entries for configuration items that override the settings in the Machine.config file. At a minimum, the Web.config file must have the <configuration> element and the <system.web> element. These elements will contain individual configuration elements.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
</system.web>
</configuration>
Web.config Setting
Connection String
< connectionStrings >
< add connectionString SQLConnectionStringname ="data source=servername;initial catalog=databasename;
integrated security=SSPI;persist security info=False;"/ >
< /connectionStrings >
App Seetings
< appSettings >
< add key="AddPath" value="http://DomainName"/ >
< /appSettings >
Session State
< sessionState timeout="60" mode="InProc" cookieless="false" > < /sessionState >
Http Runtime Excution Time
< httpRuntime executionTimeout="600" maxRequestLength="2097151" useFullyQualifiedRedirectUrl="false" minFreeThreads="12" minLocalRequestFreeThreads="6" appRequestQueueLimit="100" enableVersionHeader="true"/ >
Web Server Requesting Length
< system.webServer >
< security >
< requestFiltering >
< requestLimits maxAllowedContentLength="1073741824"/ >
< /requestFiltering >
< /security >
< /system.webServer >
Forms Authentication
< authentication mode="Forms" >
< forms name=".Autho" loginUrl="~/Login.aspx"/ >
< /authentication >
Themes Setting
< pages theme ="themename" > < /pages >
Custom Error Mode
< customErrors mode="Off" defaultRedirect="GenericErrorPage.htm" >
< error statusCode="403" redirect="NoAccess.htm"/ >
< error statusCode="404" redirect="FileNotFound.htm"/ >
< error statusCode="503" redirect="ServiceUnavailable.htm"/ >
< error statusCode="500" redirect="ServiceUnavailable.htm"/ >
< /customErrors >
Profile in Config File
< profile >
< properties >
< add name ="MyApplication" type =" System.String" defaultValue ="ApplicationValue" / >
< /properties >
< /profile >
Caching
< outputCacheSettings >
< outputCacheProfiles >
< add name="CacheApplication" duration="60" / >
< /outputCacheProfiles >
< /outputCacheSettings >
View State
< pages enableViewState="false" / >
Trace
< trace enabled="true" requestLimit="10" pageOutput="true" traceMode="SortByTime" localOnly="true"/ >
Create a Web.config File in ASP.Net
Hot on Web: