tag:blogger.com,1999:blog-78558183970175869612024-03-13T13:23:41.645-07:00Configuration Files in .Net<b>Configuration Files in .Net blog</b>, will discuss all about configuration files<br>
<big><b>
<ul>
<li>Machine.Config File
<li>Web.Config File
<li>Global.asax File
</ul>
</b></big>
<br><br>
<b><big>For .Net Articles, Links, Code and much more logon to <a href="http://www.DailyFreeCode.com">DailyFreeCode.com</a></big></b>Unknownnoreply@blogger.comBlogger10125tag:blogger.com,1999:blog-7855818397017586961.post-24439682227381961102007-05-04T15:02:00.001-07:002007-05-04T15:02:34.326-07:00What is the Global.asax used for?<p class="MsoNormal"><span style="">The Global.asax (including the Global.asax.cs file) is used to implement application and session level events. <o:p></o:p></span></p><div class="blogger-post-footer">Logon to http://www.DailyFreeCode.com for huge collection of .Net FAQ, Articles, Code, Links and much more</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7855818397017586961.post-906242057566089942007-05-04T15:01:00.001-07:002007-05-04T15:01:39.867-07:00Two types of configuration files supported by ASP.Net.Configuration files are used to control and manage the behavior of a web application.<br /><br /><ul><li>Machine.config</li><li>Web.config</li></ul><div class="blogger-post-footer">Logon to http://www.DailyFreeCode.com for huge collection of .Net FAQ, Articles, Code, Links and much more</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7855818397017586961.post-81063713485730852692007-05-04T14:57:00.003-07:002007-05-04T14:57:54.865-07:00What is Web.Config File?<p class="MsoNormal">It is an optional XML File which stores configuration details for a specific asp.net web application.<span style=""> </span><u><o:p></o:p></u></p> <p class="MsoNormal"><u>Note:</u><span style=""> </span>When you modify the settings in the <tt><span style="font-size: 10pt;">Web.Config</span></tt> file, you do not need to restart the Web service for the modifications to take effect..<span style=""> </span>By default, the <tt><span style="font-size: 10pt;">Web.Config</span></tt> file applies to all the pages in the current directory and its subdirectories.</p> <p class="MsoNormal"><u><o:p><span style="text-decoration: none;"> </span></o:p></u></p> <p class="MsoNormal"><u>Extra: </u><span style=""> </span>You can use the <tt><span style="font-size: 10pt;"><location></span></tt> tag to lock configuration settings in the <tt><span style="font-size: 10pt;">Web.Config</span></tt> file so that they cannot be overridden by a <tt><span style="font-size: 10pt;">Web.Config</span></tt> file located below it. You can use the <tt><span style="font-size: 10pt;">allowOverride</span></tt> attribute to lock configuration settings. This attribute is especially valuable if you are hosting untrusted applications on your server.</p><div class="blogger-post-footer">Logon to http://www.DailyFreeCode.com for huge collection of .Net FAQ, Articles, Code, Links and much more</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7855818397017586961.post-43892344510132010802007-05-04T14:57:00.001-07:002007-05-04T14:57:36.269-07:00What is Machine.config File?<p class="MsoNormal">The Machine.Config file, which specifies the settings that are global to a particular machine. This file is located at the following path:</p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal">\WINNT\Microsoft.NET\Framework\[Framework Version]\CONFIG\machine.config</p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"> As web.config file is used to configure one asp .net web application, same way Machine.config file is used to configure the application according to a particular machine. That is, configuration done in machine.config file is affected on any application that runs on a particular machine. Usually, this file is not altered and only web.config is used which configuring applications.<span style="font-family: Arial;"> <o:p></o:p></span></p> <p class="MsoNormal"><span style="font-family: Arial;"><o:p> </o:p></span></p> <p class="MsoNormal">You can override settings in the Machine.Config file for all the applications in a particular Web site by placing a Web.Config file in the root directory of the Web site as follows:</p> <p class="MsoNormal">\InetPub\wwwroot\Web.Config</p><div class="blogger-post-footer">Logon to http://www.DailyFreeCode.com for huge collection of .Net FAQ, Articles, Code, Links and much more</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7855818397017586961.post-1207409727248932972007-05-04T14:55:00.000-07:002007-05-04T15:00:48.399-07:00Difference between Web.Config and Machine.Config File<p style="font-family:verdana;"><span style="font-size:100%;"><span style="font-weight: bold;">Machine.Config:</span><br />i) This is automatically installed when you install Visual Studio. Net.<br />ii) This is also called machine level configuration file.<br />iii)Only one machine.config file exists on a server.<br />iv) This file is at the highest level in the configuration hierarchy.<br /><br /><span style="font-weight: bold;"> Web.Config:</span><br />i) This is automatically created when you create an ASP.Net web application project.<br />ii) This is also called application level configuration file.<br />iii)This file inherits setting from the machine.config</span><b><u><o:p></o:p></u></b></p><div class="blogger-post-footer">Logon to http://www.DailyFreeCode.com for huge collection of .Net FAQ, Articles, Code, Links and much more</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7855818397017586961.post-84941445810276267942007-05-04T14:54:00.000-07:002007-05-04T14:55:29.319-07:00What can be stored in Web.config file?<p><span style="font-size: 10pt; font-family: Arial;">There are number of important settings that can be stored in the configuration file. Here are some of the most frequently used configurations, stored conveniently inside Web.config file..</span></p> <p class="MsoNormal" style="margin-right: 0.5in; margin-left: 1in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="">1.<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span><!--[endif]--><span style="font-size: 10pt; font-family: Arial;">Database connections.</span></p> <p class="MsoNormal" style="margin-right: 0.5in; margin-left: 1in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="">2.<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span><!--[endif]--><span style="font-size: 10pt; font-family: Arial;">Session States</span> </p> <p class="MsoNormal" style="margin-right: 0.5in; margin-left: 1in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="">3.<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span><!--[endif]--><span style="font-size: 10pt; font-family: Arial;">Error Handling</span> (CustomError Page Settings.)</p> <p class="MsoNormal" style="margin-right: 0.5in; margin-left: 1in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="">4.<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span><!--[endif]--><span style="font-size: 10pt; font-family: Arial;">Security</span> (Authentication modes)</p><div class="blogger-post-footer">Logon to http://www.DailyFreeCode.com for huge collection of .Net FAQ, Articles, Code, Links and much more</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7855818397017586961.post-10643868755840255742007-05-04T14:29:00.000-07:002007-05-04T14:44:17.415-07:00What is the best place to store Database connection string in .Net?<span class="c1">In Web.Config, you would add a key to the AppSettings Section:<br /><br /> </span><br /><br /> <span class="c1"><appSettings><br /><br /> </span><br /><br /> <span class="c1"><add key=</span><span class="c2">"MyDBConnection"</span><span class="c3"> value=</span><span class="c2">"data source=<ServerName>;Initial catalog =<DBName>;user id=<Username>;password=<Password>;"</span><span class="c3"> /><br /><br /> </span><br /><br /> <span class="c1"></appSettings><br /><br /> </span><br /><br /> <span class="c1">Example:</span><br /><br /> <span class="c1"><add key=</span><span class="c2">"ConnectionString"</span><span class="c3"> value= </span><span class="c2">"data source=localhost;Initial catalog=northwind;user id=sa;password=mypass"</span><span class="c3"> /></span><br /><br /> <span class="c1">Then, </span><b class="c4">in</b><span class="c3"> your ASP.Net application - just refer to it like </span><b class="c4">this</b><span class="c3">:</span><br /><br /> <span class="c5"><b class="c4">using</b></span><span class="c3"> System.Configuration;</span><br /><br /> <span class="c5"><b class="c4">string</b></span><span class="c3"> connectionString = (</span><b class="c4">string</b><span class="c3"> )ConfigurationSettings.AppSettings[</span><span class="c2">"ConnectionString"</span><span class="c3">];<br /><br /> </span><div class="blogger-post-footer">Logon to http://www.DailyFreeCode.com for huge collection of .Net FAQ, Articles, Code, Links and much more</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7855818397017586961.post-23352963242824587712007-05-04T14:28:00.000-07:002007-05-04T14:29:13.203-07:00Hierarchy of Configuration File<p class="MsoNormal">Configuration files are arranged in hierarchy.<span style=""> </span>Child <tt><span style="font-size: 10pt;">Web.Config</span></tt> files override configuration settings specified by their parents. This means that you do not need to copy the complete contents of a parent <tt><span style="font-size: 10pt;">Web.Config</span></tt> file when creating a <tt><span style="font-size: 10pt;">Web.Config</span></tt> lower in the hierarchy. You can specify only the configuration settings that you need to modify.<span style=""> </span></p> <p class="MsoNormal"><span style="font-weight: bold;">Note:</span><span style=""> </span>If your asp.net application doesn’t consist of Web.Config file than all the settings from machine.config file would be applied.<span style=""> </span></p><div class="blogger-post-footer">Logon to http://www.DailyFreeCode.com for huge collection of .Net FAQ, Articles, Code, Links and much more</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7855818397017586961.post-23020759813459336302007-05-04T14:27:00.000-07:002007-05-04T14:28:23.520-07:00Can I use IIS as an alternative way of configuring Custom error pages?<p class="MsoNormal">Yes, you can. But the preferable way would be ASP.NET, as the ASP.NET custom pages are configured in XML based web.config (application configuration) file, resulting in easy (xcopy) deployment and management.</p><div class="blogger-post-footer">Logon to http://www.DailyFreeCode.com for huge collection of .Net FAQ, Articles, Code, Links and much more</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7855818397017586961.post-14010927989361016792007-05-02T16:03:00.000-07:002007-05-04T16:04:18.064-07:00How many web.config files for sngle application?You should have only one web.config. but in sub folder you can have one web.cofing to set configuration of that folders. example if your application have 3 folder then 4 web.config have in your application<div class="blogger-post-footer">Logon to http://www.DailyFreeCode.com for huge collection of .Net FAQ, Articles, Code, Links and much more</div>Unknownnoreply@blogger.com0