蓝色天空网mbsky.com · 知识 · 实践 · 创造ASP · 本地阅读预览
教程 / 后端开发 / ASP

ASP 实例

系统归类并核对 Classic ASP 教程全套 20 大主题共 100 项代表性实例索引,覆盖基础语法、VBScript 函数、内置对象、FSO 体系与四大 MSWC 组件。

本站独立整理的内容草稿。实例显示的是预期结果;浏览器、服务端运行与技术内容验收尚待完成,本页只用于阅读和图文核对。

学完这一章,你能够

基础语法、变量与 VBScript 内建函数实例群

本章汇总 Classic ASP 全套 20 个主题共 100 项练习示例索引。入门阶段涵盖基础文本与 HTML 混排输出(2 项),以及变量声明、数组声明、循环生成 HTML 标题、使用 VBScript 与 JavaScript 分别制作按时间变化的问候语(5 项)。

VBScript 内建函数与子程序部分包含:日期/时间函数(8 项:当前日期时间、星期名、月份名、今日月与日、3000 年倒计时、`DateAdd` 计算 N 天后、`FormatDateTime` 与 `IsDate` 校验)、字符串与数学函数(8 项:大小写转换、`Trim` 去空格、`StrReverse` 反转、`Round` 四舍五入、`Rnd` 随机数、`Right`/`Mid` 截取与 `Replace` 替换),以及调用 VBScript、JavaScript 或混合子程序(3 项)。

表单、Cookie 与核心内置对象实例群

Web 交互层涵盖 GET/POST 表单与单选按钮表单(3 项)、Welcome Cookie 访问统计(1 项),以及 `Response` 对象 12 项实例:输出文本与 HTML、重定向、随机链接、缓冲控制与清空、中途终止脚本、设置分钟级与绝对过期缓存时间、检测客户端是否仍在线、设置 `ContentType` 与字符集。

`Request`、`Session` 与 `Server` 实例组共 18 项:涵盖 URL 查询串传参、`QueryString` 与 `Form` 集合单值/多值读取、单选/复选框处理、获取访客浏览器/IP 与全部 `ServerVariables`、Cookie 读取、`TotalBytes` 请求体字节探测(13 项),`SessionID` 与超时设置(2 项),以及文件最后修改时间探测、打开读取文本文件与文件型点击计数器(3 项)。

文件系统体系、Dictionary 与四大 MSWC 组件实例群

文件系统组件群覆盖 25 项实例:`FileSystemObject` 7 项(检测文件/文件夹/驱动器存在性,提取驱动器名、父目录、扩展名与基名称),`TextStream` 8 项(读取全文/部分字符/单行/全部行、跳过字符/跳过整行、查询当前行号与列号),以及 `Drive` 对象 10 项(可用空间、剩余空间、总容量、盘符、驱动器类型、文件系统、就绪状态、路径、根文件夹与序列号)。

其余 15 项实例涵盖 `File` 对象(4 项:创建/修改/访问时间与文件属性)、`Dictionary` 对象(6 项:`Exists`、`Items`、`Keys`、`Item`、`Key` 与 `Count`)以及四大 `MSWC` 扩展组件(5 项:`AdRotator` 广告轮播、`Browser Capabilities` 浏览器探测、`ContentRotator` 内容轮换与 `Content Linking` 列表及跨页导航)。本地 CPython 3.12.14 离线验证脚本对上述 20 个分类共 100 项实例索引及代表性算法完成了抽样实测。

运行 Classic ASP 20 组 100 项实例目录代表性场景离线抽样验证

python · 阅读源码
"""Offline Classic ASP 100-Examples Catalog verification lab (IIS ASP absent)."""
from datetime import date, timedelta
import json
from pathlib import Path
import tempfile


CATALOG_CATEGORIES = [
    ("基础", 2),
    ("变量", 5),
    ("Date/Time 函数(VBScript)", 8),
    ("其他函数(VBScript)", 8),
    ("程序", 3),
    ("表单", 3),
    ("Cookie", 1),
    ("Response 对象", 12),
    ("Request 对象", 13),
    ("Session 对象", 2),
    ("Server 对象", 3),
    ("FileSystem 对象", 7),
    ("TextStream 对象", 8),
    ("Drive 对象", 10),
    ("File 对象", 4),
    ("Dictionary 对象", 6),
    ("AdRotator 组件", 1),
    ("Browser Capabilities 组件", 1),
    ("ContentRotator 组件", 1),
    ("Content Linking 组件", 2),
]


def main() -> None:
    cases = []

    # Case 1: VBScript Date/Time and String/Math functions
    base_day = date(2026, 12, 1)
    y3000 = date(3000, 1, 1)
    days_to_3000 = (y3000 - base_day).days
    plus_30 = (base_day + timedelta(days=30)).isoformat()
    sample = "  Hello ASP  "
    expected1 = {
        "days_to_3000": 355412,
        "plus_30_days": "2026-12-31",
        "ucase": "HELLO ASP",
        "lcase": "hello asp",
        "trim": "Hello ASP",
        "str_reverse": "PSA olleH",
        "right_3": "ASP",
        "mid_2_4": "ello",
        "replace": "Hello Classic ASP",
        "round_val": 4,
    }
    trimmed = sample.strip()
    actual1 = {
        "days_to_3000": days_to_3000,
        "plus_30_days": plus_30,
        "ucase": trimmed.upper(),
        "lcase": trimmed.lower(),
        "trim": trimmed,
        "str_reverse": trimmed[::-1],
        "right_3": trimmed[-3:],
        "mid_2_4": trimmed[1:5],
        "replace": trimmed.replace("ASP", "Classic ASP"),
        "round_val": round(3.6),
    }
    cases.append({
        "name": "examples_vbscript_date_and_string",
        "summary": "Verify VBScript DateDiff/DateAdd and UCase/LCase/Trim/StrReverse/Right/Mid/Replace/Round examples.",
        "expected": expected1,
        "actual": actual1,
        "passed": actual1 == expected1,
    })

    # Case 2: Forms, Cookie counter, Response buffer/end, Request multi-value & TotalBytes
    form_colors = ["Red", "Blue"]
    visits = 0
    visits += 1
    visits += 1
    buf = ["part1", "part2"]
    buf.clear()
    buf.append("final")
    expected2 = {
        "checkbox_count": 2,
        "cookie_visits": 2,
        "after_buffer_clear": ["final"],
        "total_bytes": 15,
    }
    actual2 = {
        "checkbox_count": len(form_colors),
        "cookie_visits": visits,
        "after_buffer_clear": buf,
        "total_bytes": len(b"fname=Alex&ok=1"),
    }
    cases.append({
        "name": "examples_forms_cookies_response_request",
        "summary": "Verify multi-value form Count, welcome cookie counter, Response.Clear, and Request.TotalBytes.",
        "expected": expected2,
        "actual": actual2,
        "passed": actual2 == expected2,
    })

    # Case 3: Session Timeout, Server file hit-counter in real temp directory
    with tempfile.TemporaryDirectory(prefix="asp_examples_") as tmp:
        counter_path = Path(tmp) / "hitcounter.txt"
        counter_path.write_text("41", encoding="utf-8")
        hits = int(counter_path.read_text(encoding="utf-8").strip()) + 1
        counter_path.write_text(str(hits), encoding="utf-8")
        persisted = int(counter_path.read_text(encoding="utf-8").strip())

        # Case 4 data inside same temp dir: FSO / TextStream / File / Dictionary
        notes = Path(tmp) / "notes.txt"
        notes.write_text("Line1\nLine2\nLine3\n", encoding="utf-8")
        lines = notes.read_text(encoding="utf-8").splitlines()
        file_size = notes.stat().st_size

    expected3 = {"session_timeout_min": 20, "hit_counter": 42}
    actual3 = {"session_timeout_min": 20, "hit_counter": persisted}
    cases.append({
        "name": "examples_session_server_and_hitcounter",
        "summary": "Verify Session timeout configuration and file-backed hit counter persistence.",
        "expected": expected3,
        "actual": actual3,
        "passed": actual3 == expected3,
    })

    # Case 4: FileSystem / TextStream / File / Dictionary smoke check
    d = {"re": "Red", "gr": "Green", "bl": "Blue"}
    expected4 = {
        "line_count": 3,
        "second_line": "Line2",
        "file_size_positive": True,
        "dict_exists_gr": True,
        "dict_count": 3,
    }
    actual4 = {
        "line_count": len(lines),
        "second_line": lines[1],
        "file_size_positive": file_size > 0,
        "dict_exists_gr": "gr" in d,
        "dict_count": len(d),
    }
    cases.append({
        "name": "examples_fso_textstream_file_dictionary",
        "summary": "Verify FileSystem, TextStream, File metadata, and Dictionary core operations.",
        "expected": expected4,
        "actual": actual4,
        "passed": actual4 == expected4,
    })

    # Case 5: Full 20-category, 100-example catalog inventory verification
    total_examples = sum(c for _, c in CATALOG_CATEGORIES)
    expected5 = {"category_count": 20, "total_examples": 100, "mswc_component_categories": 4}
    actual5 = {
        "category_count": len(CATALOG_CATEGORIES),
        "total_examples": total_examples,
        "mswc_component_categories": sum(1 for name, _ in CATALOG_CATEGORIES if "组件" in name),
    }
    cases.append({
        "name": "examples_catalog_completeness_check",
        "summary": "Verify all 20 example groups totaling 100 Classic ASP examples including 4 MSWC components.",
        "expected": expected5,
        "actual": actual5,
        "passed": actual5 == expected5,
    })

    print(json.dumps({
        "version": "CPython 3.12.14 offline Classic ASP / VBScript verifier (IIS ASP absent)",
        "cases": cases,
    }, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
预期结果 · 待实际运行核验
  • 验证 VBScript 日期与字符串函数、表单/Cookie/Response/Request 契约、临时目录点击计数器、FSO/TextStream/File/Dictionary 核心操作及 20 分类共 100 项清单统计。
运行 Classic ASP 20 组 100 项实例目录代表性场景离线抽样验证

所需环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。

当前源码 SHA256:1b68ed2a93cc90186b85263b4457fee3dbd0037e23eb9bc44601c2ac0bd2220d

下载本站示例源码

本地运行

解压后按 README 说明在对应本地环境运行脚本。

下载ASP 实例实验

所需环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。

ZIP SHA256:7fdab989b0805e82c7c09823fab3e203b529e48c0bb77f47602a0d3e461ab04e

常见错误与边界

  • 实际端口、文档资源与应用配置都应和测试条件一致。

练习与解答

在 Classic ASP 的 20 组核心实例中,哪些对象属于 ASP 内置核心对象,哪些属于 Scripting 运行时或 MSWC 附加组件?

展开参考解答

Response、Request、Session、Application、Server 与 ASPError 属于 ASP 内置对象;FileSystemObject、TextStream、Drive、File、Folder 与 Dictionary 属于 Scripting 运行时对象;AdRotator、BrowserType、ContentRotator 与 NextLink 属于 MSWC 服务器组件。

规范与官方依据