469,332 Members | 6,650 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

Access web.config from lower folder?

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?
Nov 20 '05 #1
5 3507
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)

Nov 20 '05 #2
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" <no@email.com> 撰寫於郵件新聞:%2****************@TK2MSFTNGP12.phx .gbl...
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?

Nov 20 '05 #3
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隳l : http://asp.net.do/foros/
======================================
"Jason Chan" <no@email.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...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?

Nov 20 '05 #4
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(ConnectionS tring).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隳l : http://asp.net.do/foros/
======================================
"Jason Chan" <no@email.com> wrote in message news:uP**************@tk2msftngp13.phx.gbl...
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" <no@email.com> 撰寫於郵件新聞:%2****************@TK2MSFTNGP12.phx .gbl...
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?

Nov 20 '05 #5
thanks , it work
"Juan T. Llibre" <no***********@nowhere.com> 撰寫於郵件新聞:%2****************@TK2MSFTNGP09.phx .gbl...
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(ConnectionS tring).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隳l : http://asp.net.do/foros/
======================================
"Jason Chan" <no@email.com> wrote in message
news:uP**************@tk2msftngp13.phx.gbl...
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" <no@email.com> 撰寫於郵件新聞:%2****************@TK2MSFTNGP12.phx .gbl...
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?


Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Peter Frost | last post: by
1 post views Thread by Microsoft News | last post: by
reply views Thread by Yogesh Pancholi | last post: by
3 posts views Thread by Rachel | last post: by
3 posts views Thread by serge calderara | last post: by
7 posts views Thread by Speech Lover | last post: by
7 posts views Thread by =?Utf-8?B?RG91Z2llIEJyb3du?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.