1

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>
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
user681119
  • 13
  • 2

1 Answers1

3

The error occurs not because you're switching between ConfigurationManager.AppSettings and AppSettings, 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.

Kon
  • 27,113
  • 11
  • 60
  • 86