gpt4 book ai didi

asp.net - 在 aspx 页面上打印 configurationmanager.appsettings 变量?

转载 作者:行者123 更新时间:2023-12-01 11:57:20 28 4
gpt4 key购买 nike

我似乎无法将 configurationmanager.appsettings 变量打印到 aspx 页面。所以在我的 index.aspx 文件中,我有以下代码行:

<%# (string) ConfigurationManager.AppSettings["myvariable"] %>

但是没有打印出来。

但是,如果我将 asp:textbox 添加到 index.aspx 页面,然后从 index.aspx.cs< 将变量绑定(bind)到它 页面如下:

textbox.Text = (string) ConfigurationManager.AppSettings["myvariable"];

然后它出现了。

如何在没有代码隐藏的情况下直接将配置变量打印到 index.aspx?

最佳答案

<%#是一个数据绑定(bind)表达式,它仅在您执行数据绑定(bind)时才计算。如果不是,则不会呈现任何内容。你应该使用 <%=改为构建:

<%= ConfigurationManager.AppSettings["myvariable"] %>

或者您可以使用更短的 <%$在这里构建例如:

<asp:Literal runat="server" Text="<%$ appSettings:myvariable%>" />

关于asp.net - 在 aspx 页面上打印 configurationmanager.appsettings 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5705268/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com