We help IT Professionals succeed at work.

Including Webconfig file in Asp.net website

TechMonster asked
Hello.  Building a asp.net webpage using VS2010. In Development studios VS will automatically add a webconfig file.   I want to reference an existing webconfig file.  So my web folder is HelloWorld and page is default.aspx.   the webconfig file is located one root up fromt the Helloworld folder.  
Watch Question

Web.config files are inherited automatically in IIS.

For instance if you have a site http://www.example.com/test
Your test application will automatically inherit the web.config at the root of http://www.example.com

Also if you don't have it set in a parent folder in IIS you could always make changes to the machine.config that will affect all asp.net web sites on the server.


In the webconfig file is housed my connection string to my DB.   So using ADO.net I can just add the following code and the $ tells it to go see the Web.Config file?

<asp:SqlDataSource ID="categoriesSource" runat="server"
             ConnectionString="<%$ ConnectionStrings:AdventureWorks %>"


Just tested it and it works.  Thanks.