Multi-lined appsettings value in web config


N

Nick Large

Hello Microsoft.

In a web config file, I intend to set a value in the appsettings as such:

<add key="ApplicationA"
value="[Application Name]:MyApp1||
[PropertyA]:proertyValue||
... "

When I compile, it replaces the CRLF with
and pushes the whole text for the item onto a single line. I intend on having a moderately large value in here.

Before anyone asks why I need this it is because, instead of having multiple keys that essentially relate to the same object, I intend on creating one single key with multiple internal values in a preset structure that I can use as a standard format. I can include stuff like connection string information and the such. I have tried the standard method and it sucks. When you look at a web.config file that has information on a complex application it gets really difficult to read the values, knowing what goes with what. This way I can group all the information together in one string, which makes sense logically.

I want to know either how to stop the designer from reordering my value-text when I compile, or how do I concatenate values in the web config, like I would in a section of code, thus: mytext = oldtext & ',' & appendedtext.

Eg. can I use

<add key="ApplicationA"
value="[Application Name]:MyApp1||" +
"[PropertyA]:proertyValue||" +
" ... "

Thanks in advance
 
Ad

Advertisements

T

Tom Dacon

Hello Microsoft.

In a web config file, I intend to set a value in the appsettings as such:

<add key="ApplicationA"
value="[Application Name]:MyApp1||
[PropertyA]:proertyValue||
... "

When I compile, it replaces the CRLF with
and pushes the whole text
for the item onto a single line. I intend on having a moderately large
value in here.

Before anyone asks why I need this it is because, instead of having multiple
keys that essentially relate to the same object, I intend on creating one
single key with multiple internal values in a preset structure that I can
use as a standard format. I can include stuff like connection string
information and the such. I have tried the standard method and it sucks.
When you look at a web.config file that has information on a complex
application it gets really difficult to read the values, knowing what goes
with what. This way I can group all the information together in one string,
which makes sense logically.

I want to know either how to stop the designer from reordering my value-text
when I compile, or how do I concatenate values in the web config, like I
would in a section of code, thus: mytext = oldtext & ',' & appendedtext.

Eg. can I use

<add key="ApplicationA"
value="[Application Name]:MyApp1||" +
"[PropertyA]:proertyValue||" +
" ... "

Thanks in advance



Nick, consider writing a custom configuration section handler, and then
placing your complex initialization stuff into its own section, in plain old
XML inside the web.config file. A little Googling, or a snoop around in the
MSDN library, should turn up the documentation on how to do this. It's not
too tough, and once it's done your data in web.config can be as complex as
you like.

Tom Dacon
Dacon Software Consulting
 
A

Allen Chen [MSFT]

Hi Nick,
Hello Microsoft.
In a web config file, I intend to set a value in the appsettings as such:
<add key="ApplicationA"
value="[Application Name]:MyApp1||
[PropertyA]:proertyValue||
... "
When I compile, it replaces the CRLF with
and pushes the whole text
for the item onto a single line.

Based on my test, normal ASP.NET Application will not change CRLF in its
web.config with &#xA after compile. My guess is you're using Web
development project, right? If so please refer to my previous case to learn
how to use custom task to replace a string in web.config:

http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=micros
oft.public.dotnet.framework.aspnet&tid=dd83befb-d870-40dc-bcb4-8a49fc5f85d4&
cat=&lang=&cr=&sloc=&p=1

Your probably need to write a custom action to do this. Please use
Reflector to view the source code of:

MSBuild.ExtensionPack.FileSystem.File

and write your custom action class.

Please let me know whether my understanding is correct and whether above
approach can solve this issue.

Regards,
Allen Chen
Microsoft Online 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: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 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. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

germ

forget the line feeds and use just use a delimiter
<add key="ApplicationA"
value="[Application Name]:MyApp1|[PropertyA]:proertyValue|... " />
Hello Microsoft.

In a web config file, I intend to set a value in the appsettings as such:

<add key="ApplicationA"
value="[Application Name]:MyApp1||
[PropertyA]:proertyValue||
... "

When I compile, it replaces the CRLF with
and pushes the whole text for the item onto a single line. I intend on having a moderately large value in here.

Before anyone asks why I need this it is because, instead of having multiple keys that essentially relate to the same object, I intend on creating one single key with multiple internal values in a preset structure that I can use as a standard format. I can include stuff like connection string information and the such. I have tried the standard method and it sucks. When you look at a web.config file that has information on a complex application it gets really difficult to read the values, knowing what goes with what. This way I can group all the information together in one string, which makes sense logically.

I want to know either how to stop the designer from reordering my value-text when I compile, or how do I concatenate values in the web config, like I would in a section of code, thus: mytext = oldtext & ',' & appendedtext.

Eg. can I use

<add key="ApplicationA"
value="[Application Name]:MyApp1||" +
"[PropertyA]:proertyValue||" +
" ... "

Thanks in advance
 
G

Guest

Hello Microsoft.

In a web config file, I intend to set a value in the appsettings as such:

<add key="ApplicationA"
   value="[Application Name]:MyApp1||
          [PropertyA]:proertyValue||
            ... "

When I compile, it replaces the CRLF with
and pushes the whole text for the item onto a single line.  I intend on having a moderately large value in here.

For me it works.

in the web.config file

<appSettings>
<add key="ApplicationA" value="[Application Name]:MyApp1||
[PropertyA]:proertyValue||
..." />
</appSettings>

in aspx

Response.Write("test=");
Response.Write(ConfigurationManager.AppSettings
["ApplicationA"]);
Response.End();

output

test=[Application Name]:MyApp1||
[PropertyA]:proertyValue||
...

So, where is the problem?

(.net 2.0)
 
N

Nick Large

Hello Alexey,

It seems to happen under some circumstance that I dont know of because I
copied the text back over the ruined value and saved, and have not
experienced this issue since, although when I used the web deployment
project and deployed it, the web config in the destination was messed up in
the same way. I wonder if this is internmittent functionality? I was
hoping to use this as a standard web config value so I write a dll to read
these values into a class library and include that in my project, then
simply refer to the values using the hierarchy that I define in the object
produced by the library.

Nick.


Hello Microsoft.

In a web config file, I intend to set a value in the appsettings as such:

<add key="ApplicationA"
value="[Application Name]:MyApp1||
[PropertyA]:proertyValue||
... "

When I compile, it replaces the CRLF with
and pushes the whole text
for the item onto a single line. I intend on having a moderately large
value in here.

For me it works.

in the web.config file

<appSettings>
<add key="ApplicationA" value="[Application Name]:MyApp1||
[PropertyA]:proertyValue||
..." />
</appSettings>

in aspx

Response.Write("test=");
Response.Write(ConfigurationManager.AppSettings
["ApplicationA"]);
Response.End();

output

test=[Application Name]:MyApp1||
[PropertyA]:proertyValue||
...

So, where is the problem?

(.net 2.0)
 
Ad

Advertisements

N

Nick Large

I use a delimiter but I find that the most revolting thing that a programmer can do is have their code stretch so far along that by the time you have reached the middle of the code you have already forgotten about the begining of the code. Microsofts 'Code Complete' book outlines this, but their XML files do not abide by this rule.

Thanks for the suggestion but I go by the rule that if you have to use the horizontal scrollbar, that your code needs reformatting, period. Its the same as saying if I write the same section of code 100 times then I should maybe put that section in a function and call it instead. It is about cutting down into palatable chunks.

Nick.
forget the line feeds and use just use a delimiter
<add key="ApplicationA"
value="[Application Name]:MyApp1|[PropertyA]:proertyValue|... " />
Hello Microsoft.

In a web config file, I intend to set a value in the appsettings as such:

<add key="ApplicationA"
value="[Application Name]:MyApp1||
[PropertyA]:proertyValue||
... "

When I compile, it replaces the CRLF with
and pushes the whole text for the item onto a single line. I intend on having a moderately large value in here.

Before anyone asks why I need this it is because, instead of having multiple keys that essentially relate to the same object, I intend on creating one single key with multiple internal values in a preset structure that I can use as a standard format. I can include stuff like connection string information and the such. I have tried the standard method and it sucks. When you look at a web.config file that has information on a complex application it gets really difficult to read the values, knowing what goes with what. This way I can group all the information together in one string, which makes sense logically.

I want to know either how to stop the designer from reordering my value-text when I compile, or how do I concatenate values in the web config, like I would in a section of code, thus: mytext = oldtext & ',' & appendedtext.

Eg. can I use

<add key="ApplicationA"
value="[Application Name]:MyApp1||" +
"[PropertyA]:proertyValue||" +
" ... "

Thanks in advance
 
N

Nick Large

Hi Allen.

This issue appears to be intermittent. I will do my best to try and repro
this properly again. It had this behavior the first time I deployed, so I
copied the correct layout back over it and recompiled and have not gottent
the saame issue since, but, as I say I will try and repro again and reply
back.

I dont think that what you point it is entirely what I ask but I will leave
it until I can repro with 100% accuracy before I continue with this post.

Thanks.

Allen Chen said:
Hi Nick,
Hello Microsoft.
In a web config file, I intend to set a value in the appsettings as such:
<add key="ApplicationA"
value="[Application Name]:MyApp1||
[PropertyA]:proertyValue||
... "
When I compile, it replaces the CRLF with
and pushes the whole text
for the item onto a single line.

Based on my test, normal ASP.NET Application will not change CRLF in its
web.config with &#xA after compile. My guess is you're using Web
development project, right? If so please refer to my previous case to
learn
how to use custom task to replace a string in web.config:

http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=micros
oft.public.dotnet.framework.aspnet&tid=dd83befb-d870-40dc-bcb4-8a49fc5f85d4&
cat=&lang=&cr=&sloc=&p=1

Your probably need to write a custom action to do this. Please use
Reflector to view the source code of:

MSBuild.ExtensionPack.FileSystem.File

and write your custom action class.

Please let me know whether my understanding is correct and whether above
approach can solve this issue.

Regards,
Allen Chen
Microsoft Online 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: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 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. Issues of this
nature are best handled working with a dedicated Microsoft Support
Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
 
N

Nick Large

Hi Allen.

I did repro the issue with 100% accuracy.
I used the web deployment project (Project -> Create Web Deployment Project)
which I always use to deploy applications so that I don't have to copy
source
files to the deployment server, leaving code open.
Anyway, if you have a web.config with keys in the appsettings that have
newlines in, then deploy, go to the resultant deployment files and open the
web.config
file, it will add
to each spot that you have a newline, therefore
messing up
your nice structure that you spend so long building in order to avoid
fragmenting
related data into hundreds of separate web keys, therefore making
application
development unmanageable.

I thought that Visual studio was supposed to be a reliable development tool.
I see that
this kind of unwanted behaviour shows to the opposite. Any idea how I can
deploy
my files either without using the Web Deployment tool which messes it up,
or how do I find and turn off the option "please mess with my files" - I
dont see it anywhere?

Thanks, Nick.

Nick Large said:
Hi Allen.

This issue appears to be intermittent. I will do my best to try and repro
this properly again. It had this behavior the first time I deployed, so I
copied the correct layout back over it and recompiled and have not gottent
the saame issue since, but, as I say I will try and repro again and reply
back.

I dont think that what you point it is entirely what I ask but I will
leave it until I can repro with 100% accuracy before I continue with this
post.

Thanks.

Allen Chen said:
Hi Nick,
Hello Microsoft.
In a web config file, I intend to set a value in the appsettings as such:
<add key="ApplicationA"
value="[Application Name]:MyApp1||
[PropertyA]:proertyValue||
... "
When I compile, it replaces the CRLF with
and pushes the whole text
for the item onto a single line.

Based on my test, normal ASP.NET Application will not change CRLF in its
web.config with &#xA after compile. My guess is you're using Web
development project, right? If so please refer to my previous case to
learn
how to use custom task to replace a string in web.config:

http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=micros
oft.public.dotnet.framework.aspnet&tid=dd83befb-d870-40dc-bcb4-8a49fc5f85d4&
cat=&lang=&cr=&sloc=&p=1

Your probably need to write a custom action to do this. Please use
Reflector to view the source code of:

MSBuild.ExtensionPack.FileSystem.File

and write your custom action class.

Please let me know whether my understanding is correct and whether above
approach can solve this issue.

Regards,
Allen Chen
Microsoft Online 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: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 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. Issues of
this
nature are best handled working with a dedicated Microsoft Support
Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
 
A

Allen Chen [MSFT]

Hi Nick,
I thought that Visual studio was supposed to be a reliable development tool.
I see that
this kind of unwanted behaviour shows to the opposite. Any idea how I can
deploy
my files either without using the Web Deployment tool which messes it up,
or how do I find and turn off the option "please mess with my files" - I
dont see it anywhere?

Thanks for your update. If you want to use Web Deployment project please
refer to my previous reply to work around this issue. Writing a custom
action can solve this problem. The action can be reused for other Web
Deployment projects. Or you can manually replace the web.config file after
msbuild the project.
I always use to deploy applications so that I don't have to copy
source
files to the deployment server, leaving code open.

If you don't want to use Web Deployment project I believe you'll not see
this issue. It's also possible to publish web project/web site without
publishing source code.

For web site, you can right click the site node in solution explorer window
and select "Publish Web Site". On the Publish Web Site window, uncheck
"Allow this precompiled site to be updatable".

For web application project, please run the following command to precompile
it:

aspnet_compiler -p "path of your web application project folder" -v / "path
of the output web site folder"

Then you can simply copy&paste it to server to publish it.

Please let me know if it can solve this issue and feel free to ask if you
have additional questions. I'll do my best to follow up.

Regards,
Allen Chen
Microsoft Online 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).
 
G

Guest

Hello Alexey,

It seems to happen under some circumstance that I dont know of because I
copied the text back over the ruined value and saved, and have not
experienced this issue since, although when I used the web deployment
project and deployed it, the web config in the destination was messed up in
the same way.  I wonder if this is internmittent functionality?  I was
hoping to use this as a standard web config value so I write a dll to read
these values into a class library and include that in my project, then
simply refer to the values using the hierarchy that I define in the object
produced by the library.

Nick.


Hello Microsoft.
In a web config file, I intend to set a value in the appsettings as such:
<add key="ApplicationA"
value="[Application Name]:MyApp1||
[PropertyA]:proertyValue||
... "
When I compile, it replaces the CRLF with
and pushes the whole text
for the item onto a single line. I intend on having a moderately large
value in here.

For me it works.

in the web.config file

    <appSettings>
        <add key="ApplicationA" value="[Application Name]:MyApp1||
            [PropertyA]:proertyValue||
            ..." />
    </appSettings>

in aspx

            Response.Write("test=");
            Response.Write(ConfigurationManager.AppSettings
["ApplicationA"]);
            Response.End();

output

test=[Application Name]:MyApp1||
            [PropertyA]:proertyValue||
            ...

So, where is the problem?

(.net 2.0)

Ok, why not to replace the < || > by < ||+line_break > in the code
then? I think this would be easiest way if you don't want to create
custom configuration section in the web.config. Of course, this is bad
if line breaks are killed by web deployment. On another hand, this is
xml and you either have to encode, or use CDATA wrapper to handle
special characters.
 
Ad

Advertisements

N

Nick Large

Thanks Allen, just for the record I used a work around - in my code I trim
out the unwanted whitespace text in a function I call TrimWhitespace. This
does the job but of course it doesn't help to resolve the issue that the web
config appears in a brutal straight line. For production I intend on taking
a copy of the web.config from my source and copying it to the staging
directory prior to deployment - that should do the trick, but it is an extra
workaround that could have been avoided.

Thanks again I will look at your alternative to Web Deployment Projects,
although WDP's are habitual nowadays so I'm not sure about changing this
part of the process as I am currently used to it.

Nick.
 

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