{"id":331,"date":"2003-03-26T18:25:45","date_gmt":"2003-03-26T22:25:45","guid":{"rendered":"http:\/\/wordpress.cephas.net\/?p=331"},"modified":"2003-03-26T18:25:45","modified_gmt":"2003-03-26T22:25:45","slug":"systemapp-configuration-in-net","status":"publish","type":"post","link":"https:\/\/cephas.net\/blog\/2003\/03\/26\/systemapp-configuration-in-net\/","title":{"rendered":"System\/App Configuration in .NET"},"content":{"rendered":"<p>I mentioned I&#8217;m working with .NET stuff on my current project.  One of the nicer features I&#8217;ve found so far is that .NET includes an entire package devoted to <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpref\/html\/frlrfsystemconfiguration.asp\">System\/App Configuration<\/a>. So I I&#8217;m writing an web application, I can put a web.config file in the root of my app and\/or any of the subdirectories of my application.  Inside that web.config file,  I can set security, modify the compiler setting, specify an error handler&#8230; you get the picture.  IMHO, the best part is that you can extend web.config and add your own custom settings.  For instance, almost every web application worth a look uses some sort of database, which usually requires a database connection string or DSN name.  You&#8217;d add something like this:<\/p>\n<p>&lt;appSettings&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&lt;add key=&#8221;connectionString&#8221; value=&#8221;user id=sa;password=mypassword;initial catalog=mydb;data source=mydbserver;Connect Timeout=30&#8243; \/&gt;<br \/>\n&lt;\/appSettings&gt;<\/p>\n<p>outside of the system.web tag. To use that value in your application, you need not parse the xml file, you don&#8217;t have to worry about getting it into application scope, you don&#8217;t need to worry about locking.  You only need to write one line of code:<\/p>\n<p>private static String CONNECTIONSTRING = System.Configuration.ConfigurationSettings.AppSettings[&#8220;connectionString&#8221;].ToString();<\/p>\n<p>Pretty simple isn&#8217;t it?  It gets better. According to this <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpguide\/html\/cpconaspnetconfiguration.asp\">document<\/a>, &#8220;<i>ASP.NET detects changes to configuration files and automatically applies new configuration settings to Web resources affected by the changes. The server does not have to be rebooted for the changes to take effect.<\/i>&#8221; and more importantly, &#8220;<i>ASP.NET protects configuration files from outside access by configuring Internet Information Services (IIS) to prevent direct browser access to configuration files.<\/i>&#8221;<\/p>\n<p>Further Resources: <\/p>\n<p>ASP.NET Configuration: [<a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpguide\/html\/cpconaspnetconfiguration.asp\">source<\/a>]<br \/>\nFormat of ASP.NET Configuration Files: [<a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpguide\/html\/cpconformatofconfigurationfiles.asp\">source<\/a>]<br \/>\nConfiguring Applications in .NET: [<a href=\"http:\/\/www.c-sharpcorner.com\/Code\/2002\/June\/ConfigApp.asp\">source<\/a>]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I mentioned I&#8217;m working with .NET stuff on my current project. One of the nicer features I&#8217;ve found so far is that .NET includes an entire package devoted to System\/App Configuration. So I I&#8217;m writing an web application, I can put a web.config file in the root of my app and\/or any of the subdirectories &hellip; <a href=\"https:\/\/cephas.net\/blog\/2003\/03\/26\/systemapp-configuration-in-net\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">System\/App Configuration in .NET<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/331"}],"collection":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/comments?post=331"}],"version-history":[{"count":0,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/331\/revisions"}],"wp:attachment":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/media?parent=331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/categories?post=331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/tags?post=331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}