I have question: when I to use <%= ConfigurationManager.AppSettings["xxx"] %> and <%$ AppSettings: xxx %>.
Sometimes when I use <%= ConfigurationManager.AppSettings["xxx "] %> a I got the following error: “Server tags cannot contain <% … %> constructs”. Then a put <%$ AppSettings: xxx %> and it works.
Like this example:
Error:
<asp:Literal runat="server" ID="Literal9" Text="<%= ConfigurationManager.AppSettings["xxx"] %>"></asp:Literal>
Working:
<asp:Literal runat="server" ID="Literal9" Text='<%$ AppSettings: xxx %>'></asp:Literal>
The error occurs not because you’re switching between
ConfigurationManager.AppSettingsandAppSettings, but because of the symbol used after<%. You can’t have code rendering markup inside a server-side control that renders markup. The second way works because it evaluates the expression prior to server-side control render.My preference is to always use
ConfigurationManager.AppSettings, because it’s more clear as to what the code is accessing.