What are appSettings keys valid characters? - asp.net

This is strange. I thought I would easily find this information googling, but I haven't had much success. All I want to know is what are the valid characters that can be used for the keys in the AppSettings section of a Web.config file. Eg:
<add key="MySpeed" value="100" />
<add key="My.Speed" value="100" />
<add key="My Speed" value="100" />
<add key="Vélocité" value="100" />
Would all of the above keys be permitted?

The Microsoft documentation states only that the key is a String attribute. Nothing more. Their examples do show a key with spaces in the name.

Related

How do you enable document function in XSLT (called from ASP.NET)?

I have a stylesheet using a for each loop over the XML doc but when it comes accross using the document() method it fails.
<td >
<xsl:value-of select="document('Departments.xml')/Departments/Department[#Id=dep]/Name"/>
</td>
The variable has a value each loop which prints out
Execution of the "document()" function was prohibited. Use the
"XsltSettings.EnableDocumentFunction" property to enable it.
I think if XslCompiledTransform is used by the asp:xml control instead of XslTransform it means that the environment you are working in has set aspnet:RestrictXmlControls to true (https://learn.microsoft.com/en-us/previous-versions/aspnet/hh975440(v=vs.120))
<appSettings>
<add key="aspnet:RestrictXmlControls" value="true" />
</appSettings>
so you might need to try/check whether your locale web.config can set it back to
<appSettings>
<add key="aspnet:RestrictXmlControls" value="false" />
</appSettings>
to have XslTransform being used where you are not restricted by default XsltSettings.

Populating choices in an ASP.NET ComboBox from web.config

There are several answered questions detailing how to refer to a single value from web.config file. I'd like to maintain lists of values with which to populate combo boxes in the Views. Should I use some sort of key/value pair structure, with the key identifying the particular combo box to populate?
<add key="CalculationMethod" value="Fixed"/>
<add key="CalculationMethod" value="Cost Plus"/>
<add key="CalculationMethod" value="Formula"/>
I'm not sure how I'd read this, or if that would even work (don't keys have to be unique?). The IntelliSense for web.config doesn't seem to allow much in the appSettings section that looks applicable to a more robust structure like
<list name="CalculationMethod">
<item value="Fixed"/>
<item value="Cost Plus"/>
<item value="Formula"/>
</list>
I see that the root <configuration> has a lot of options for children, but which one to use, if any?
You really should be using a database for something like this but if you must put it in the web.config then you could delimit the values and parse them out at run time.
<add key="CalculationMethod" value="Fixed,Cost Plus,Formula"/>
myComboBox.DataSource = new List<String>(lstrCalcMethodsFromWebConfig.Split(','));

Share Localization

I was able to localize my Alfresco Model (plus constraints lists) by following these rules :
http://wiki.alfresco.com/wiki/Data_Dictionary_Guide#Model_Localization
But I would like to know if there is something similar for Share?
Do we only have to use the "label-id" attributes without worrying of any convention?
Is it better to use :
label.companyName=Company name
or something like
sop_sopModel.field.sop_companyName.title=Company Name
or anything else ?
I didn't see any recommandation on the wiki.
Here is an example of label-ids I don't know how to format.
This is a part of my share-config-custom.xml file.
I know this is not really important but I would like to do things properly.
<config evaluator="aspect" condition="sop:company">
<forms>
<form>
<field-visibility>
<show id="sop:companyName" />
<show id="sop:companyAddress" />
</field-visibility>
<appearance>
<set id="sopPanel" appearance="bordered-panel" label-id="???" />
<field id="sop:companyName" label-id="???" set="sopPanel" />
<field id="sop:companyAddress" label-id="???" set="sopPanel" />
</appearance>
</form>
</forms>
</config>
You don't normally need to use the label-id attribute. If your model definition has a message bundle associated with it then the correct labels for your current locale will come through from the repository automatically.

Getting list of key values from app config with same name

I have follwing in app.config file:
<appSettings>
<add key="Name" value="Office"/>
...
<add key="Name" value="HotSpot"/>
...
<add key="Name" value="Home"/>
</appSettings>
I tried
ConfigurationManager.AppSettings["Name"]
But it only gives me one Value? How can i get list of all values? I am using c# 3.5. Is there lambda expression or something i can use to get that?
You can only use one key per value, so this approach will not work.
There are two alternate approaches I can think of:
Use a single key with a delimiter, and retrieve with ConfigurationManager.AppSettings["Name"].Split(new [] { "," });.
<add key="Name" value="Office,Hotspot,Home" />
Use a custom section to create a section that can contain your array of strings.

Is it possible to have an ampersand sign in an appSettings key? error: web.config value is not defined

I have the following appSettings section
<appSettings>
<add key="Foo" value="http://foo.bar.com/?app=xxx&FormName=yyy" />
</appSettings>
But the IDE is giving me two errors:
Error 25 Entity 'FormName' not defined.
Error 26 Expecting ';'.
It seems the & is causing a problem. I'd like to not have to splt the values up into seperate keys. Is there an elegant way around this issue?
You just need to use XML encoding here I believe - so & becomes &
Try &
<appSettings>
<add key="Foo" value="http://foo.bar.com/?app=xxx&FormName=yyy" />
</appSettings>

Resources