how to direct web.config to use sections in subfolders?

J

JRL

Can you recommend a way to reference a subfolder for the web.config file?

I have a section in the root web.config file for a site and it works when I
include parts of the config file as external sections.
So for example, the following works:
<connectionStrings configSource="rconnection.config" />
It loads a little file with the connection string in the rconnection.config
file, which sits at the same root level as web.config

Now, what if I wanted to clean up the solution explorer view, by putting
this little file in a directory called configuration. I tried this change:

<connectionStrings configSource="~/configuration/rconnection.config" />

The above file generates an error, as it will not allow relative paths.

How can I call the file within a subdirectory? Is there a special path
descriptor that will avoid the use of '/' yet still allow a subdirectory?
 
M

Mr. Arnold

JRL said:
Can you recommend a way to reference a subfolder for the web.config file?

I have a section in the root web.config file for a site and it works
when I include parts of the config file as external sections.
So for example, the following works:
<connectionStrings configSource="rconnection.config" />
It loads a little file with the connection string in the
rconnection.config file, which sits at the same root level as web.config

Now, what if I wanted to clean up the solution explorer view, by putting
this little file in a directory called configuration. I tried this change:

<connectionStrings configSource="~/configuration/rconnection.config" />

The above file generates an error, as it will not allow relative paths.

How can I call the file within a subdirectory? Is there a special path
descriptor that will avoid the use of '/' yet still allow a subdirectory?

It's at the bottom of the article.

http://www.odetocode.com/Articles/345.aspx
 
J

JRL


The sample you referenced is very similar to what I am currently using. The
example it uses:
<appSettings file="testlabsettings.config"/>

also references a file at the same (root) level of the solution.

What is the format I would use if I wanted to direct it to a file within a
folder?
Given that I cannot use the \ character.
 
C

Colbert Zhou [MSFT]

Hello Jeff,

The limitation of configSource attribute is that it only supports
configuration files that are in the same directory as or a child directory
of the main config file. Using a relative parent directory (e.g.
"..\included.config") or an absolute path ("c:\temp\included.config") will
cause an error. This limitation is as per design for the security
consideration. For more information, you can read,
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?Feedba
ckID=93626&wa=wsignin1.0

But based on your description, we can call the file in a sub directory just
using the following,
<connectionStrings configSource ="configuration\rconnection.config"/>

If we use the "~/configuration/rconnection.config", we will receive the
error, "The configSource attribute must be a relative physical path, so the
'/' character is not allowed". Please let me know if you have any future
questions or concerns, and I will be more than happy to be of future
assistance.

Have a nice day!


Best regards,
Colbert Zhou (colbertz @online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

JRL

Thank you, this variant of the file location string did allow me to nest the
files.

Problem solved!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top