Global Web.Config Settings

Posted on: Thu Oct 23 16:59:04 -0700 2008. Updated on: Thu Oct 23 17:21:45 -0700 2008.
Category: DotNet

Placing certain configuration global variables in the web.config can be very useful. It can save you having to re-deploy your application to production, which can in some scenarios be a scary thing. It also gives you a centralized place for keeping track of important constant variables, which you can access from anywhere in your app

To extract the variable it depends on where in the structure of your site it is located. If you simply have an app with one web.config, it is quite simple and Intellisense helps you our. If you have multiple apps within an app, and the app setting you want is in the website root web.config, use the second method below.

// standard method
string connectString = myproject.Properties.Settings.Default.SettingsConnectionString;

// website root web.config
connectString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];

To place the Global setting in your project visually, simply: Right Click on the Properties Folder at the top of your Project and choose Open. Click the "Settings" tab on the left, and you will see the application settings listed.

To place the settings manually, edit your Web.config and add the following code, editing for your needs.


    
      
        SQL SERVER: blah/blah etc USEMIRROR=true
      
    

Comments:

Add a Comment:

simple_captcha.jpg
(human authentication)


Ads

Categories

About

Random foliage

This website is meant to be a reference for ASP Dot Net developers. The entries are a compilation of things I've figured out how to do and that I deem useful to keep of track for future reference. Assumptions: web development with: C Sharp (vb sucks), visual studio 05/08, .net 3.5, meant for programmers. Written by: James Reategui.