Share via


Working with Web.config Files

Applies to: SharePoint Foundation 2010

You may need to modify web.config files to make your solution work in the Microsoft SharePoint Foundation environment. For example, you might need to add a SafeControl entry, register an HttpModule, or customize SessionState, but a SharePoint Foundation deployment includes numerous web.config files. For example, there is one for each Web application and a copy of each of these is on every front-end web server.

To make customizing web.config files easier, SharePoint Foundation provides two ways to make changes. First, you can declaratively register web.config entries by creating an XML file that contains a set of web.config modifications. To do this, you create a custom webconfig.XYZ.xml file deployed to %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\CONFIG, where XYZ is a unique ID that you use to identify your solution. For an example that shows how to create a custom web.config file to change settings, see How to: Create a Supplemental .config File.

In addition to creating a supplemental webconfig.XYZ.xml file, you can use the SharePoint Foundation object model to modify web.config settings. For an example that shows how to modify settings programmatically, see How to: Add and Remove Web.config Settings Programmatically.

Changes that you define through the object model or through XML are always applied when you create a Web application.

Web.config File Locations

Web.config files are contained in the following folders within the file system:

  • \\Inetpub\wwwroot\wss\VirtualDirectories\Port_Number — The web.config file that defines configuration settings for a SharePoint content Web application.

  • \\Inetpub\wwwroot\wss\VirtualDirectories\Port_Number_of_Central_Administration — The web.config file that defines configuration settings for the SharePoint Central Administration application.

  • \\Inetpub\wwwroot\wss\VirtualDirectories\Port_Number\wpresources — The web.config file used in the Web application's Web Part resources.

  • \\Program Files\Common Files\Microsoft Shared\Web Server Extensions\wpresources — A web.config file that is used in Web Part resources for the global assembly cache.

    Important

    The web.config files in the \wpresources folders should not be modified. The settings of these files disallow pages or items that can be compiled. If these settings are changed, the security state for the compiled code differs greatly from the security state for code that runs from the Local_Drive:\Inetpub\wwwroot directory.

  • %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\CONFIG — The web.config file and other .config files that together define configuration settings for extending other Web applications.

  • %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\ISAPI — The web.config file that defines configuration settings for the /_vti_bin virtual directory.

  • %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\LAYOUTS — The web.config file that defines configuration settings for the /_layouts virtual directory.

When a SharePoint Foundation Web application is created, a top-level web.config file is placed within the content root folder of the Web application, which defines configuration settings for the server such as HTTP handling for Web Parts. Another web.config file used for Web Part resources is placed in a \wpresources folder within the same root folder.

Warning

Changes that you make to any of the web.config files that are built into SharePoint Foundation, or that are created when a SharePoint Foundation Web application is created, may be overwritten when you install updates or service packs for SharePoint Foundation, or when you upgrade an installation to the next product version. For this reason, we recommend that you not directly edit these files. Make changes to web.config settings using either the method described in How to: Create a Supplemental .config File or the method described in How to: Add and Remove Web.config Settings Programmatically. With either method, your custom settings can be reapplied post-upgrade.

In This Section

See Also

Tasks

How to: Find the Web Application Root