<%$, <%@, <%=, <%# ... 怎么回事? [英] <%$, <%@, <%=, <%# ... what's the deal?
问题描述
我用经典的 ASP 和 ASP.NET 编程,我在服务器端代码的标记中看到了不同的标记.
I've programmed in both classic ASP and ASP.NET, and I see different tags inside of the markup for server side code.
我最近遇到了一个 MSDN 上的好博客 介绍了两者之间的区别:
I've recently come across a good blog on MSDN that goes over the difference between:
<%=
(百分比加上等号)和<%#
(百分号和哈希/磅/八索)
<%=
(percentage together with equals sign) and<%#
(percent sign and hash/pound/octothorpe)
(<%#
仅在数据绑定时评估,而 <%=
在渲染时评估),但我也看到:
(<%#
is evaluated only at databind, and <%=
is evaluated at render), but I also see:
<%$
(百分比和美元符号)和<%@
(百分号和 at 符号).
<%$
(percent and dollar sign) and<%@
(percent sign and at symbol).
我相信 <%@
加载程序集之类的东西,也许 <%$
从配置文件加载东西?我不太确定.
I believe <%@
loads things like assemblies and perhaps <%$
loads things from config files? I'm not too sure.
我只是想知道是否有人可以为我澄清所有这些,并可能解释为什么创建这么多看似具有相似目的的不同标签很重要?
I was just wondering if anyone could clarify all of this for me and possibly explain why it's important to create so many different tags that seemingly have a similar purpose?
推荐答案
<% %>
- 用于 内联代码(尤其是逻辑流程)<%$ %>
- 用于 评估表达式(如资源变量)<%@%>
- 用于 页面指令、注册程序集、导入命名空间等<%= %>
- 是Response.Write
的简写(讨论 这里)<%# %>
- 用于数据绑定表达式.<%: %>
- 是 Response.Write(Server.HTMLEncode()) ASP.net 4.0+<%#: %>
- 用于数据绑定表达式并自动进行HTML编码.<%-- --%>
- 用于 服务器端评论<% %>
- is for inline code (especially logic flow)<%$ %>
- is for evaluating expressions (like resource variables)<%@ %>
- is for Page directives, registering assemblies, importing namespaces, etc.<%= %>
- is short-hand forResponse.Write
(discussed here)<%# %>
- is used for data binding expressions.<%: %>
- is short-hand for Response.Write(Server.HTMLEncode()) ASP.net 4.0+<%#: %>
- is used for data binding expressions and is automatically HTMLEncoded.<%-- --%>
- is for server-side comments
这篇关于<%$, <%@, <%=, <%# ... 怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!