How to: Create Web.config Files (2024)

  • Article

ASP.NET uses a hierarchy of XML text files, each named Web.config, to store settings that control how your Web site works. Using the features of the ASP.NET configuration system, you can configure an entire server, an ASP.NET application, or individual pages. This topic describes how to create a Web.config file in Visual Web Developer.

To create a Web.config file

  1. In Solution Explorer, click the Refresh icon to make sure that a Web.config file does not already exist for your application.

    If you have already used the Web Site Administration Tool or some other means of configuring your application, a Web.config file might have been created automatically. Clicking Refresh updates your file list.

  2. In Solution Explorer, right-click your Web site name, and then click Add New Item.

  3. In the Templates window, click Web Configuration File.

    The file name in the Name text box should be Web.config. You can give the file another name, but this is the default. The .config file name extension is protected from being downloaded by ASP.NET.

  4. Click Add to create the file and open it for editing.

    The file contains the code shown in the "Example" section later in this topic, with a few initial defaults. Your application inherits all configuration settings from the Machine.config and Web.config files in the %SystemRoot%\Microsoft.NET\Framework\<version>\CONFIG directory, but you will not see those default settings here. Application-level or directory-level Web.config files only need to be created if you want to override the inherited default settings or add to collection elements like httpHandlers.

    To view all of the configuration settings for your current application, you could run the code included in the topic How to: View Inherited and Local Configuration Settings Programmatically. Alternatively, you can view the Machine.config.comments or Web.config.comments files (which also contain useful comments) in the %SystemRoot%\Microsoft.NET\Framework\<version>\CONFIG directory, but these two files will not contain all of your run-time settingsHow to: View Inherited and Local Configuration Settings Programmatically.

  5. If you have changed your Web.config file, save it.

    Saving a Web.config file restarts the application. You can alternatively use the configSource attribute of individual section elements to point to a secondary configuration file that does not cause an application restart when it is changed. For more information, see configSource in General Attributes Inherited by Section Elements.

To use IntelliSense to edit configuration settings

  1. In Visual Web Developer, open your Web.config file.

  2. In the editing window, place your cursor inside the <system.web> </system.web> tags on a line by itself, but not inside any other tags.

  3. Type the less-than character (<) to start a new element.

    A drop-down list appears that offers valid elements to add at this insertion point. Alternatively, you can press Ctrl+J to display the drop-down list without typing the less-than character.

  4. Select anonymousIdentification.

    The anonymouseIdentification element is placed in your Web.config file and is terminated. If an element is terminated by a closing tag, then there are available child elements that you can set. If an element is terminated, like the following anonymousIdentification element, there are no available child elements to set.

    <anonymousIdentification />
  5. Place your cursor within the <anonymousIdentification /> tag, and then press the SPACEBAR key.

    A drop-down list appears that offers valid attributes to add to the anonymousIdentification element. Alternatively, you can press Ctrl+J to display the drop-down list without pressing the SPACEBAR key.

  6. Select enabled.

    The enabled attribute is placed in your Web.config file, and because it is a Boolean attribute, the values of true and false are offered in a drop-down list.

  7. Select false. This is the system default.

    The IntelliSense system makes suggestions for elements and attributes that are available at the insertion point. Sometimes, specialized attributes are not offered. For example, when configuring a providers element, such as for the siteMap element, different attributes are available depending on the type of provider you are adding. IntelliSense does not show these attributes because they depend upon the value of the type attribute.

  8. Change the value of the enabled attribute to "falsex", which is an invalid value.

    The IntelliSense system provides validation checking and displays a squiggly line under any text that does not validate.

Example

The following code example illustrates the initial contents of a Web.config file created by Visual Web Developer. Default settings are given for the compilation and the authentication elements. To turn on ASP.NET debugging, all you would do is change the debug attribute of the compilation element to true. All of the elements that can appear within the system.web element are documented in ASP.NET Configuration Settings.

<?xml version="1.0"?><!-- Note: As an alternative to hand editing this file you can use the Web Site Administration Tool to configure settings for your application. Use the Web site->Asp.Net Configuration option in Visual Studio. A full list of settings and comments can be found in machine.config.comments usually located in \Windows\Microsoft.Net\Framework\v2.x\Config --><configuration xmlns="https://schemas.microsoft.com/.NetConfiguration/v2.0"> <appSettings/> <connectionStrings/> <system.web> <!-- Set compilation debug="true" to insert debugging symbols into the compiled page. Because this affects performance, set this value to true only during development. --> <compilation debug="false"/> <!-- The <authentication> section enables configuration of the security authentication mode used by ASP.NET to identify an incoming user. --> <authentication mode="Windows"/> <!-- The <customErrors> section enables configuration of what to do if/when an unhandled error occurs during the execution of a request. Specifically, it enables developers to configure html error pages to be displayed in place of a error stack trace. <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm"/> <error statusCode="404" redirect="FileNotFound.htm"/> </customErrors> --> </system.web></configuration>

Security

When storing sensitive information in a configuration file for an application, you should encrypt the sensitive values using protected configuration. For more information about this and other security issues for configuration files, see Securing ASP.NET Configuration.

See Also

Concepts

ASP.NET Configuration Overview

ASP.NET Configuration File Hierarchy and Inheritance

Web Site Administration Tool Overview

ASP.NET Configuration File Hierarchy and Inheritance

Securing ASP.NET Configuration

Configuration How-to Topics

Other Resources

ASP.NET Configuration Files

How to: Create Web.config Files (2024)
Top Articles
What Is the Rule of 72?
Routing Number: What It Is And How To Find Yours | Bankrate
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Geoffrey Lueilwitz

Last Updated:

Views: 5928

Rating: 5 / 5 (60 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Geoffrey Lueilwitz

Birthday: 1997-03-23

Address: 74183 Thomas Course, Port Micheal, OK 55446-1529

Phone: +13408645881558

Job: Global Representative

Hobby: Sailing, Vehicle restoration, Rowing, Ghost hunting, Scrapbooking, Rugby, Board sports

Introduction: My name is Geoffrey Lueilwitz, I am a zealous, encouraging, sparkling, enchanting, graceful, faithful, nice person who loves writing and wants to share my knowledge and understanding with you.