Access web.config from lower folder?

Discussion in 'ASP .Net' started by Jason Chan, Nov 17, 2005.

  1. Jason Chan

    Jason Chan Guest

    I have a subfolder in a webapp

    How can the aspx in the subfolder access the web.config in the webapp.

    I.e. I stored the connectionstring in the \webapp\web.config
    how the \webapp\subfolder\default.aspx extract the connection?

    ConfigurationSettings.AppSettings["ConnectionString"] return empty string

    Do I have to copy the web.config to the subfolder?
     
    Jason Chan, Nov 17, 2005
    #1
    1. Advertising

  2. Jason Chan

    Jason Chan Guest

    seem that the ConfigurationSettings.AppSettings["ConnectionString"] is not
    the correct statment to extract the string in asp.net 2.0, becos I cannot do
    it even in webapp

    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    <appSettings/>
    <connectionStrings>
    <add name="ConnectionString" connectionString="Data Source=...."
    ProviderName="System.Data.SqlClient"/>
    </connectionStrings>


    "Jason Chan" <> ¼¶¼g©ó¶l¥ó·s»D:%...
    I have a subfolder in a webapp

    How can the aspx in the subfolder access the web.config in the webapp.

    I.e. I stored the connectionstring in the \webapp\web.config
    how the \webapp\subfolder\default.aspx extract the connection?

    ConfigurationSettings.AppSettings["ConnectionString"] return empty string

    Do I have to copy the web.config to the subfolder?
     
    Jason Chan, Nov 17, 2005
    #2
    1. Advertising

  3. Jason Chan

    gadget_guru Guest

    no, web.config should be in the root folder of the app.
    The way you mention should work - does
    ConfigurationSettings.AppSettings["ConnectionString"] work in the
    rootfolder ? (maybe something is wrong in the syntax of web.config)
     
    gadget_guru, Nov 17, 2005
    #3
  4. re:
    > How can the aspx in the subfolder access the web.config in the webapp.


    It does it without having to do anything special.

    re:
    > Do I have to copy the web.config to the subfolder?


    No, you don't.

    Check your syntax.

    If you want to, post the web.config appSettings section
    ( change any sensitive information, like passwords, if any )
    and the line of code which you are using to retrieve the info.

    string connect = ConfigurationSettings.AppSettings["ConnectionString"];
    returns empty and your web.config's appSettings have a key like :

    <appSettings>
    <add key="ConnectionString" value="SomeConnectionStringtoYourDB" />
    </appSettings>

    ?



    Juan T. Llibre, ASP.NET MVP
    ASP.NET FAQ : http://asp.net.do/faq/
    ASPNETFAQ.COM : http://www.aspnetfaq.com/
    Foros de ASP.NET en Español : http://asp.net.do/foros/
    ======================================
    "Jason Chan" <> wrote in message
    news:%...
    >I have a subfolder in a webapp
    >
    > How can the aspx in the subfolder access the web.config in the webapp.
    >
    > I.e. I stored the connectionstring in the \webapp\web.config
    > how the \webapp\subfolder\default.aspx extract the connection?
    >
    > ConfigurationSettings.AppSettings["ConnectionString"] return empty string
    >
    > Do I have to copy the web.config to the subfolder?
    >
    >
     
    Juan T. Llibre, Nov 17, 2005
    #4
  5. You should have said you were using ASP.NET 2.0 from the start.

    Actually, ConfigurationSettings.AppSettings["ConnectionString"]
    WILL return data from an <appSettings...> section which does
    *not* have the <connectionStrings> section.

    If you *do* include a <connectionStrings> section, then you can use :

    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

    or

    String connString =
    ConfigurationManager.ConnectionStrings(ConnectionString).ConnectionString




    Juan T. Llibre, ASP.NET MVP
    ASP.NET FAQ : http://asp.net.do/faq/
    ASPNETFAQ.COM : http://www.aspnetfaq.com/
    Foros de ASP.NET en Español : http://asp.net.do/foros/
    ======================================
    "Jason Chan" <> wrote in message news:...
    > seem that the ConfigurationSettings.AppSettings["ConnectionString"] is not
    > the correct statment to extract the string in asp.net 2.0, becos I cannot do
    > it even in webapp
    >
    > <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    > <appSettings/>
    > <connectionStrings>
    > <add name="ConnectionString" connectionString="Data Source=...."
    > ProviderName="System.Data.SqlClient"/>
    > </connectionStrings>
    >
    >
    > "Jason Chan" <> ¼¶¼g©ó¶l¥ó·s»D:%...
    > I have a subfolder in a webapp
    >
    > How can the aspx in the subfolder access the web.config in the webapp.
    >
    > I.e. I stored the connectionstring in the \webapp\web.config
    > how the \webapp\subfolder\default.aspx extract the connection?
    >
    > ConfigurationSettings.AppSettings["ConnectionString"] return empty string
    >
    > Do I have to copy the web.config to the subfolder?
    >
    >
    >
     
    Juan T. Llibre, Nov 17, 2005
    #5
  6. Jason Chan

    Jason Chan Guest

    thanks , it work
    "Juan T. Llibre" <> ¼¶¼g©ó¶l¥ó·s»D:%...
    You should have said you were using ASP.NET 2.0 from the start.

    Actually, ConfigurationSettings.AppSettings["ConnectionString"]
    WILL return data from an <appSettings...> section which does
    *not* have the <connectionStrings> section.

    If you *do* include a <connectionStrings> section, then you can use :

    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

    or

    String connString =
    ConfigurationManager.ConnectionStrings(ConnectionString).ConnectionString




    Juan T. Llibre, ASP.NET MVP
    ASP.NET FAQ : http://asp.net.do/faq/
    ASPNETFAQ.COM : http://www.aspnetfaq.com/
    Foros de ASP.NET en Español : http://asp.net.do/foros/
    ======================================
    "Jason Chan" <> wrote in message
    news:...
    > seem that the ConfigurationSettings.AppSettings["ConnectionString"] is not
    > the correct statment to extract the string in asp.net 2.0, becos I cannot
    > do
    > it even in webapp
    >
    > <configuration
    > xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    > <appSettings/>
    > <connectionStrings>
    > <add name="ConnectionString" connectionString="Data Source=...."
    > ProviderName="System.Data.SqlClient"/>
    > </connectionStrings>
    >
    >
    > "Jason Chan" <> ¼¶¼g©ó¶l¥ó·s»D:%...
    > I have a subfolder in a webapp
    >
    > How can the aspx in the subfolder access the web.config in the webapp.
    >
    > I.e. I stored the connectionstring in the \webapp\web.config
    > how the \webapp\subfolder\default.aspx extract the connection?
    >
    > ConfigurationSettings.AppSettings["ConnectionString"] return empty string
    >
    > Do I have to copy the web.config to the subfolder?
    >
    >
    >
     
    Jason Chan, Nov 17, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. THY
    Replies:
    3
    Views:
    2,988
    Alvin Bruney
    Oct 16, 2003
  2. KQ
    Replies:
    1
    Views:
    467
  3. =?Utf-8?B?bGVueWFkbw==?=
    Replies:
    2
    Views:
    437
    =?Utf-8?B?bGVueWFkbw==?=
    May 20, 2005
  4. Benny Ng
    Replies:
    9
    Views:
    10,252
    Benny Ng
    Oct 13, 2005
  5. CSharpner
    Replies:
    0
    Views:
    1,145
    CSharpner
    Apr 9, 2007
Loading...

Share This Page