从用户控件引用 appSettings
在我的 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
应该可以工作(至少在我使用的 IIS 服务器上可以)。 (不幸的是它更冗长)
should work (it at least does on the IIS server I use). (Unfortunately it's more verbose)
编辑:不要忘记=
EDIT:Don't forget the =
代替
尝试使用.ascx
在后面的代码中
Try this instead
.ascx
in code behind
接下来会有更准确的答案:
More accurate answer will be next:
使用冒号代替点并添加
runat="server"
:文档在这一点上不是很清楚,但 ASP.Net 表达式用于服务器标记内。 因此,如果您想在纯 html 标记中使用它,则必须添加
runat="server"
以便在计算表达式的服务器上处理该标记。Use a colon instead of a dot and add
runat="server"
: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.