请原谅我对 ASP 的无知,但有什么区别?
最佳答案
这些在某种程度上被非正式地称为“蜜蜂蜇伤”。有4种类型:<%# %>
在 DataBinding 阶段调用。<%= %>
用于从代码获取值到 UI 层。旨在向后兼容 ASP 应用程序。不应该在 .NET 中使用。<%@ %>
代表directives并允许在不借助代码的情况下设置行为。<%: %>
(在 ASP.NET 4 中引入)与 %=
相同,但增加了 HtmlEncoding 输出的功能。目的是将此作为默认用法(超过 %=
),以帮助屏蔽脚本注入(inject)攻击。
Directives specify settings that are used by the page and user-control compilers when the compilers process ASP.NET Web Forms pages (.aspx files) and user control (.ascx) files.
ASP.NET treats any directive block (<%@ %>) that does not contain an explicit directive name as an @ Page directive (for a page) or as an @ Control directive (for a user control).
@Esteban - 添加了一个指向指令的 msdn 链接。如果您需要...更多解释,请告诉我。
关于.net - <%# %> 和 <%= %> 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/160097/