从用户控件引用 appSettings

发布于 2024-07-19 04:40:02 字数 393 浏览 5 评论 0原文

在我的 .ascx 用户控件中,我尝试使用存储在 web.config 中的值动态生成链接。

<a href="<%$appSettings.MYPATH%>/file.aspx">link</a>

当我尝试运行时,我收到解析器错误,

Literal expressions like '<%$appSettings.MYPATH %>' are not allowed. Use <asp:Literal runat="server" Text="<%$appSettings.MYPATH%>" /> instead.

我知道我可能缺少一些相对较小的东西。

In my .ascx usercontrol i'm trying to dynamically generate links using a value i've stored in web.config.

<a href="<%$appSettings.MYPATH%>/file.aspx">link</a>

and when i try running, i get a parser error

Literal expressions like '<%$appSettings.MYPATH %>' are not allowed. Use <asp:Literal runat="server" Text="<%$appSettings.MYPATH%>" /> instead.

I know i'm probably missing something relatively minor.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

暗藏城府 2024-07-26 04:40:02
    <a href="<%= System.Configuration.ConfigurationManager.appSettings("MYPATH") %>">link</a>

应该可以工作(至少在我使用的 IIS 服务器上可以)。 (不幸的是它更冗长)

    <a href="<%= System.Configuration.ConfigurationManager.appSettings("MYPATH") %>">link</a>

should work (it at least does on the IIS server I use). (Unfortunately it's more verbose)

墨小沫ゞ 2024-07-26 04:40:02
<%= ConfigurationManager.AppSettings["myKey"] %>

编辑:不要忘记=

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

EDIT:Don't forget the =

慕烟庭风 2024-07-26 04:40:02

代替

尝试使用.ascx

<asp:Literal ID="Literal1" runat="server"></asp:Literal>

在后面的代码中

Literal1.Text = "<a href='" + appSettings.MYPATH + "'/file.aspx">link</a>"

Try this instead

.ascx

<asp:Literal ID="Literal1" runat="server"></asp:Literal>

in code behind

Literal1.Text = "<a href='" + appSettings.MYPATH + "'/file.aspx">link</a>"
自在安然 2024-07-26 04:40:02

接下来会有更准确的答案:

<a href="<%= System.Configuration.ConfigurationManager.AppSettings["param_name"] %>">Link</a>

More accurate answer will be next:

<a href="<%= System.Configuration.ConfigurationManager.AppSettings["param_name"] %>">Link</a>
浮云落日 2024-07-26 04:40:02

使用冒号代替点并添加 runat="server"

<a href="<%$ AppSettings: MYPATH %>/file.aspx">link</a>

文档在这一点上不是很清楚,但 ASP.Net 表达式用于服务器标记内。 因此,如果您想在纯 html 标记中使用它,则必须添加 runat="server" 以便在计算表达式的服务器上处理该标记。

Use a colon instead of a dot and add runat="server":

<a href="<%$ AppSettings: MYPATH %>/file.aspx">link</a>

The documentation isn't very clear on this point, but ASP.Net Expressions are for use within server tags. Thus, if you want to use one in a plain html tag, you must add runat="server" so that the tag is processed on the server where the expression will be evaluated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文