![](/img/trans.png)
[英]appSettings and ConfigurationManager.AppSettings issue
[英]ConfigurationManager.AppSettings or only AppSettings?
我有一個問題:何時使用<%= ConfigurationManager.AppSettings["xxx"] %>
和<%$ AppSettings: xxx %>
。
有時當我使用<%= ConfigurationManager.AppSettings["xxx "] %>
出現以下錯誤:“服務器標記不能包含<%…%>構造”。 然后放一個<%$ AppSettings: xxx %>
。
像這個例子:錯誤:
<asp:Literal runat="server" ID="Literal9" Text="<%= ConfigurationManager.AppSettings["xxx"] %>"></asp:Literal>
工作:
<asp:Literal runat="server" ID="Literal9" Text='<%$ AppSettings: xxx %>'></asp:Literal>
發生此錯誤的原因不是因為您正在ConfigurationManager.AppSettings
和AppSettings
之間切換,而是因為<%
之后使用了符號。 您不能在呈現標記的服務器端控件中包含代碼呈現標記。 第二種方法之所以有效,是因為它在服務器端控件渲染之前先評估表達式。
我的偏好是始終使用ConfigurationManager.AppSettings
,因為它更清楚代碼正在訪問什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.