Results 1 to 3 of 3

Thread: Understanding Web.Config *RESOLVED*

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    Cape Cod, US
    Posts
    292

    Understanding Web.Config *RESOLVED*

    I'm using the config file for storing some application-wide settings. So I have an entry like this in web.config:

    <appSettings>
    &nbsp&nbsp<add key="A" value="whatever" />
    </appSettings>


    I then grab the value for a key like like this:

    ConfigurationSettings.AppSettings("A")

    Nothing special so far...

    But what I've also got is a web app nested within another web app, so it kind of looks like:

    Parent Virtual Directory
    &nbsp;&nbsp;Web.Config (Key="A"...)
    &nbsp;&nbsp;Parent.aspx
    &nbsp;&nbsp;Child Virtual Directory
    &nbsp;&nbsp;&nbsp;&nbsp;Web.Config (Key="B"...)
    &nbsp;&nbsp;&nbsp;&nbsp;Child.aspx

    The behavior I'm seeing is the Child code can retreive a config setting defined at the parent level. In other words in the above example, child.aspx can make 2 calls :

    ConfigurationSettings.AppSettings("A")
    ConfigurationSettings.AppSettings("B")


    and get a value for each, but each value is coming from a different config file.

    Is this legitimate stuff? Understanding better will really help me out. Thanks!
    Last edited by fungi; Feb 10th, 2003 at 11:19 AM.

  2. #2
    Fanatic Member Redth's Avatar
    Join Date
    May 2001
    Location
    Ontario, Canada
    Posts
    551
    well, this is how it works...

    if you don't have a web.config file in a subfolder of the folder above it, the subfolder will use the web.config file from the folder that the subfolder is in...

    example...

    VB Code:
    1. wwwroot
    2.    -MySite
    3.     Web.Config
    4.        -MySubFolder
    5.         Web.Config

    If -MySubFolder didn't contain a web.config, all settings from the wwwroot/MySite/Web.Config file would apply to all files in MySubFolder....

    and even if you do have a Web.Config file in MySubFolder, all settings that are specified in wwwroot/MySite/Web.Config apply to MySubFolder, unless the Web.Config file in MySubFolder specifies otherwise...

    it's kind of like inheritable permissions in winnt/2k/xp... it assumes all the settings of the parent directory's config file unless the setting is specific in the owner's own config file...

    that is why your Key A and Key B both work.... try putting the A Key, and a different value for Key A in the child directorie's config file... it will return that value...

    i hope that's somewhat clear.. it's late and it's hard for me to get my point across in words

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    Cape Cod, US
    Posts
    292
    Thanks redth, you clarified nicely just what I was suspecting. Any ideas on where I'd look to find this information discussed officially like in MSDN?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width