ASP 简介
ASP 的运行机制、文件结构、与静态 HTML 的差别。
Key PointsASP 文件由 IIS 的 asp.dll 处理:先执行脚本、再输出 HTML,所以能按请求生成不同内容。
运行机制
Text
浏览器 ──GET /hello.asp──▶ IIS
│
├─ 静态文件(.html/.css/.jpg)→ 直接返回
└─ .asp → 交给 asp.dll 执行脚本
↓
生成 HTML
↓
浏览器 ◀──────── HTML ────────────────┘IIS decides by extension: .html is served as-is, .asp goes to the ASP engine. Rename an ASP page to .html and the <% %> blocks appear verbatim in the page.
ASP 文件里能放什么
| Content | Handled by |
|---|---|
| HTML / CSS / JS | 原样发到浏览器 |
<% ... %> | 服务器执行 |
<%= ... %> | 服务器执行后插入结果 |
<!-- #include --> | 服务器在编译前合并 |
和静态页的差别
HTML
<!-- static.html:每个人看到的都一样 -->
<p>当前时间:不会变化</p>ASP
<%-- dynamic.asp:每次请求都重新生成 --%>
<p>当前时间:<%= Now() %></p>
<p>你的 IP:<%= Request.ServerVariables("REMOTE_ADDR") %></p>Output
当前时间:2026/11/3 14:25:09
你的 IP:203.0.113.42The same URL can return different content on every request. That is the essence of a dynamic page: the server assembles content before responding.
常用内置对象
- Request —— 读客户端传来的参数、头、Cookie
- Response —— 写输出、设头、重定向
- Session —— 每个用户一份的会话数据
- Application —— 全站共享的数据
- Server —— 创建对象、编码、映射路径
ASP has no real compilation step; the script is parsed per request. That makes development convenient but far slower than compiled frameworks, and IIS CPU saturates easily under load.
运行机制
Text
浏览器 ──GET /hello.asp──▶ IIS
│
├─ 静态文件(.html/.css/.jpg)→ 直接返回
└─ .asp → 交给 asp.dll 执行脚本
↓
生成 HTML
↓
浏览器 ◀──────── HTML ────────────────┘IIS 按扩展名决定怎么处理:.html 直接读文件返回,.asp 交给 ASP 引擎执行。所以把 ASP 页面改名成 .html,里面的 <% %> 会原样出现在页面上。
ASP 文件里能放什么
| 内容 | 由谁处理 |
|---|---|
| HTML / CSS / JS | 原样发到浏览器 |
| 服务端脚本 | 服务器执行 |
| 输出表达式 | 服务器执行后插入结果 |
| 包含指令 | 服务器在编译前合并 |
和静态页的差别
HTML
<!-- static.html:每个人看到的都一样 -->
<p>当前时间:不会变化</p>ASP
<%-- dynamic.asp:每次请求都重新生成 --%>
<p>当前时间:<%= Now() %></p>
<p>你的 IP:<%= Request.ServerVariables("REMOTE_ADDR") %></p>Output
当前时间:2026/11/3 14:25:09
你的 IP:203.0.113.42同一个 URL,两次请求返回的内容可以完全不同。这是动态页面的本质——服务器在返回前拼装内容。
常用内置对象
- Request —— 读客户端传来的参数、头、Cookie
- Response —— 写输出、设头、重定向
- Session —— 每个用户一份的会话数据
- Application —— 全站共享的数据
- Server —— 创建对象、编码、映射路径
ASP 没有真正的「编译」阶段,每次请求都要解析脚本。这让它开发调试方便,但性能远低于编译型框架——高并发场景下 IIS 的 CPU 很容易打满。