Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Multi-lined appsettings value in web config

 
Thread Tools Search this Thread
Old 11-05-2009, 08:16 PM   #1
Default Multi-lined appsettings value in web config


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]roertyValue||
... "

When I compile, it replaces the CRLF with &#xA; 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]roertyValue||" +
" ... "

Thanks in advance


Nick Large
  Reply With Quote
Old 11-05-2009, 10:33 PM   #2
Tom Dacon
 
Posts: n/a
Default Re: Multi-lined appsettings value in web config

"Nick Large" <> wrote in message
news:...
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]roertyValue||
... "

When I compile, it replaces the CRLF with &#xA; 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]roertyValue||" +
" ... "

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




Tom Dacon
  Reply With Quote
Old 11-06-2009, 02:36 AM   #3
Allen Chen [MSFT]
 
Posts: n/a
Default RE: Multi-lined appsettings value in web config
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]roertyValue||
> ... "
>When I compile, it replaces the CRLF with &#xA; 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...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:
.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#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/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.






Allen Chen [MSFT]
  Reply With Quote
Old 11-06-2009, 04:58 AM   #4
germ
 
Posts: n/a
Default Re: Multi-lined appsettings value in web config
forget the line feeds and use just use a delimiter
<add key="ApplicationA"
value="[Application Name]:MyApp1|[PropertyA]roertyValue|... " />
"Nick Large" <> wrote in message news:...
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]roertyValue||
... "

When I compile, it replaces the CRLF with &#xA; 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]roertyValue||" +
" ... "

Thanks in advance


germ
  Reply With Quote
Old 11-06-2009, 08:17 AM   #5
Alexey Smirnov
 
Posts: n/a
Default Re: Multi-lined appsettings value in web config
On Nov 5, 9:16*pm, "Nick Large" <msnew...@nospam.nospam> wrote:
> 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]roertyValue||
> * * * * * * ... "
>
> When I compile, it replaces the CRLF with &#xA; 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]roertyValue||
..." />
</appSettings>

in aspx

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

output

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

So, where is the problem?

(.net 2.0)


Alexey Smirnov
  Reply With Quote
Old 11-06-2009, 03:25 PM   #6
Nick Large
 
Posts: n/a
Default Re: Multi-lined appsettings value in web config
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.


"Alexey Smirnov" <> wrote in message
news:fd83a068-1376-422c-b173-...
On Nov 5, 9:16 pm, "Nick Large" <msnew...@nospam.nospam> wrote:
> 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]roertyValue||
> ... "
>
> When I compile, it replaces the CRLF with &#xA; 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]roertyValue||
..." />
</appSettings>

in aspx

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

output

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

So, where is the problem?

(.net 2.0)




Nick Large
  Reply With Quote
Old 11-06-2009, 03:29 PM   #7
Nick Large
 
Posts: n/a
Default Re: Multi-lined appsettings value in web config
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.
"germ" <> wrote in message news:%...
forget the line feeds and use just use a delimiter
<add key="ApplicationA"
value="[Application Name]:MyApp1|[PropertyA]roertyValue|... " />
"Nick Large" <> wrote in message news:...
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]roertyValue||
... "

When I compile, it replaces the CRLF with &#xA; 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]roertyValue||" +
" ... "

Thanks in advance


Nick Large
  Reply With Quote
Old 11-06-2009, 03:39 PM   #8
Nick Large
 
Posts: n/a
Default Re: Multi-lined appsettings value in web config
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 [MSFT]" <> wrote in message
news:...
> 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]roertyValue||
>> ... "
>>When I compile, it replaces the CRLF with &#xA; 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...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:
> .
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/en-us/subs...#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/subs.../aa948874.aspx
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>
>
>





Nick Large
  Reply With Quote
Old 11-10-2009, 04:31 PM   #9
Nick Large
 
Posts: n/a
Default Re: Multi-lined appsettings value in web config
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 &#xD;&#xA; 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" <> wrote in message
news:...
> 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 [MSFT]" <> wrote in message
> news:...
>> 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]roertyValue||
>>> ... "
>>>When I compile, it replaces the CRLF with &#xA; 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...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:
>> .
>>
>> ==================================================
>> Get notification to my posts through email? Please refer to
>> http://msdn.microsoft.com/en-us/subs...#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/subs.../aa948874.aspx
>> ==================================================
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>>
>>
>>

>
>





Nick Large
  Reply With Quote
Old 11-11-2009, 03:41 AM   #10
Allen Chen [MSFT]
 
Posts: n/a
Default Re: Multi-lined appsettings value in web config
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:
.



Allen Chen [MSFT]
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Carsoft, PARTS 1-7 A-B, Car Diagnostic and Tunning equipment, Dashboard tools, Workshop manuals ola@mail.gr Computer Support 0 11-07-2007 08:59 PM
How not to blow a fuse? computers and a multi plug w/ surge protector jameshanley39@yahoo.co.uk Computer Information 3 09-19-2007 04:54 PM
Mac Stuff CDs, A to Z, updated 2006/November/06, and Win & Mac programs, 'WinMac', 'PC/MaC', 'Win-Mac', 'Multi', 'Multi-Platform', 'MultiFormat', 'MULTIOS', 'HYBRID' kashumoto_tokugawa Computer Information 0 11-07-2006 05:08 PM
Spoke to Spoke Enhanced Config (ASA-PIX) NEED HELP ASAP!! T-Mak Hardware 1 10-27-2006 11:56 AM
Burning CD's (Long - error log included) fiddaman64 Computer Support 11 05-11-2005 01:49 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46