Why is the classic ASP server-side include enclosed in a comment?

大憨熊 提交于 2019-12-23 20:15:31

问题


Why is the syntax for server-side inclusion <!--#include file="suchandsuch"-->?

Placing semantically meaningful content inside a comment seems awkward and misleading – indeed, the first time I saw this syntax, I assumed it was an include that had been "commented out". What was the reasoning behind designing the language to use this syntax, as opposed to alternatives like <% #include file="suchandsuch" %>?

(I'm aware that parsing that example alternative with simple substitution would render something like <% <% vbscript_stuff %> html_stuff %>, but it should be trivial to parse it a little more intelligently to avoid misusing HTML comments.)


回答1:


I think the main reason is the server side processing in the case of server side includes is handled directly by IIS then passed off to the processing engine the content is related to.

So using the example in the question, if the syntax was;

<% #include file="suchandsuch" %>

then it's dealing direct with ASP processing syntax which means the SSI definition is no longer generic in it's approach.

As stated in the MSDN Library documentation

This directive can be used in an ASP page, STM page, INC page, or any page with a file name extension that is mapped to the SSI interpreter (Ssinc.dll) or to the ASP interpreter (Asp.dll). If you have IIS Manager installed, you can modify default application mappings and add new mappings.

Also as the <!-- --> comment is processed server side it never reaches the client's browser so HTML semantics are unaffected.


Useful Links

  • IIS: Notes on Server-Side Includes (SSI) Syntax (KB 203064 Revisited)



回答2:


Server-side includes (and their "comment-style" format) are not confined to ASP/IIS -- it was used to enable the idea of server-side macros that would be processed by the server directly without rendering as text on the client.

Here's a helpful summary: http://en.wikibooks.org/wiki/Active_Server_Pages/Server-Side_Includes



来源:https://stackoverflow.com/questions/25162502/why-is-the-classic-asp-server-side-include-enclosed-in-a-comment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!