2011-03-28 28 views
1

我有問題:當我使用<%= ConfigurationManager.AppSettings["xxx"] %><%$ AppSettings: xxx %>ConfigurationManager.AppSettings或只有AppSettings?

有時當我使用<%= 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> 

回答

3

不是因爲你ConfigurationManager.AppSettingsAppSettings之間切換時出現錯誤,但由於<%之後使用的符號。您不能在呈現標記的服務器端控件中呈現代碼呈現標記。第二種方法是有效的,因爲它在服務器端控制渲染之前評估表達式。

我的首選是總是使用ConfigurationManager.AppSettings,因爲它更清楚代碼訪問的內容。

相關問題