|
|
@@ -2,32 +2,32 @@ |
|
|
|
|
|
|
|
|
Rules for developing Classic ASP applications that run on **AxonASP** (Go-based Classic ASP / VBScript 5.8 runtime, https://github.com/guimaraeslucas/axonasp). |
|
|
Rules for developing Classic ASP applications that run on **AxonASP** (Go-based Classic ASP / VBScript 5.8 runtime, https://github.com/guimaraeslucas/axonasp). |
|
|
|
|
|
|
|
|
Sources: the AxonASP manual (`deploy/www/manual/md`, notably `authoring/llm-classic-asp-coding.md`, `asp/*`, `asp-modernization/*`, `runtime/*`, `config/*`, `libraries/*`) plus problems verified while porting this project. Items marked **[verified here]** were reproduced in this repo's container; the rest come from the manual. |
|
|
|
|
|
|
|
|
Sources: the AxonASP manual (in the container at `/opt/axonasp/www/manual/md`, notably `authoring/llm-classic-asp-coding.md`, `asp/*`, `asp-modernization/*`, `runtime/*`, `config/*`, `libraries/*`) plus problems verified while porting this project. Items marked **[verified here]** were reproduced in this repo's container; the rest come from the manual. |
|
|
|
|
|
|
|
|
When unsure about an object, ProgID, method or config key, check `deploy/www/manual/md` before guessing. Do not invent APIs. |
|
|
|
|
|
|
|
|
When unsure about an object, ProgID, method or config key, check `/opt/axonasp/www/manual/md` in the container before guessing. Do not invent APIs. |
|
|
|
|
|
|
|
|
--- |
|
|
--- |
|
|
|
|
|
|
|
|
## 1. Project layout and how to run it |
|
|
## 1. Project layout and how to run it |
|
|
|
|
|
|
|
|
``` |
|
|
``` |
|
|
asp-classic-unified-framework/ the application (MVC starter, "RouteKit") |
|
|
|
|
|
|
|
|
(repo root) the application (MVC starter, "RouteKit"), also the git repo root |
|
|
public/ web root (Default.asp front controller + routes, web.config, api/*.openapi.json specs) |
|
|
public/ web root (Default.asp front controller + routes, web.config, api/*.openapi.json specs) |
|
|
core/ framework code (autoload_core.asp, mvc.asp, lib.*.asp incl. lib.JsonLite.asp, helpers.asp) |
|
|
core/ framework code (autoload_core.asp, mvc.asp, lib.*.asp incl. lib.JsonLite.asp, helpers.asp) |
|
|
app/ controllers/ (HTML: <Name>Controller, JSON: Api<Name>Controller), models/ (POBO_<T>, <T>Repository), |
|
|
app/ controllers/ (HTML: <Name>Controller, JSON: Api<Name>Controller), models/ (POBO_<T>, <T>Repository), |
|
|
views/<Name>/ |
|
|
views/<Name>/ |
|
|
db/ app.sqlite (SQLite) and migrations/ |
|
|
|
|
|
|
|
|
db/ app.sqlite (SQLite, git-ignored) and migrations/ |
|
|
scripts/ migrate.cmd/.asp, gen.cmd (generators: migration, repo, controller, api), templates/ (POBO, |
|
|
scripts/ migrate.cmd/.asp, gen.cmd (generators: migration, repo, controller, api), templates/ (POBO, |
|
|
Repository, Api). Run through the AxonASP CLI in the container. |
|
|
Repository, Api). Run through the AxonASP CLI in the container. |
|
|
|
|
|
docker-compose.yml the AxonASP container (stock image ghcr.io/guimaraeslucas/axonasp) |
|
|
api-tests/ created by `gen.cmd api`: <table>.http sample requests (VS Code REST Client) |
|
|
api-tests/ created by `gen.cmd api`: <table>.http sample requests (VS Code REST Client) |
|
|
deploy/ Dockerfile, docker-compose.yml, app/ (AxonASP linux binaries + config/axonasp.toml) |
|
|
|
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
- Run: `cd deploy && docker compose up -d --build` -> http://localhost:8801 |
|
|
|
|
|
- Compose mounts the whole framework folder at `/opt/axonasp/site` and sets `SERVER_WEB_ROOT=/opt/axonasp/site/public`. This keeps `../core`, `../app`, `../db` reachable from `public/`. |
|
|
|
|
|
|
|
|
- Run: `docker compose up -d` from the repo root -> http://localhost:8801 |
|
|
|
|
|
- Compose mounts the whole repo at `/opt/axonasp/site` and sets `SERVER_WEB_ROOT=/opt/axonasp/site/public`. This keeps `../core`, `../app`, `../db` reachable from `public/`, and is the layout `gen.cmd` / `migrate.cmd` expect (container name must be `axonasp`). |
|
|
- Migrations: `scripts\migrate.cmd status|up|down` (runs `axonasp-cli` inside the container). |
|
|
- Migrations: `scripts\migrate.cmd status|up|down` (runs `axonasp-cli` inside the container). |
|
|
- Swagger UI for the JSON APIs: http://localhost:8801/api/docs (needs internet: loads Swagger UI from the jsDelivr CDN). |
|
|
- Swagger UI for the JSON APIs: http://localhost:8801/api/docs (needs internet: loads Swagger UI from the jsDelivr CDN). |
|
|
- `deploy/www/` is the stock AxonASP demo site and manual. It is not part of this app. |
|
|
|
|
|
|
|
|
- The AxonASP manual is inside the container: `docker exec axonasp ls /opt/axonasp/www/manual/md` (libraries/, asp/, runtime/, ...). There is no `deploy/` folder in this repo. |
|
|
|
|
|
|
|
|
### Adding a table end to end (the workflow that was verified) |
|
|
### Adding a table end to end (the workflow that was verified) |
|
|
|
|
|
|
|
|
@@ -89,7 +89,7 @@ The portable rules in section 2 remain the default for framework and application |
|
|
|
|
|
|
|
|
## 5. Objects and libraries |
|
|
## 5. Objects and libraries |
|
|
|
|
|
|
|
|
Create objects with `Server.CreateObject("ProgID")` using exact ProgIDs from `deploy/www/manual/md/libraries/overview.md`. Names are case-insensitive. AxonASP maps ProgIDs to native Go implementations; it does not use the Windows registry or COM. |
|
|
|
|
|
|
|
|
Create objects with `Server.CreateObject("ProgID")` using exact ProgIDs from `/opt/axonasp/www/manual/md/libraries/overview.md` (in the container). Names are case-insensitive. AxonASP maps ProgIDs to native Go implementations; it does not use the Windows registry or COM. |
|
|
|
|
|
|
|
|
- **Prefer native libraries over hand-rolled ASP:** `G3JSON`, `G3DB`, `G3HTTP`, `G3CRYPTO`, `G3MAIL`, `G3FILES`, `G3TEMPLATE`, `G3MD`, `G3IMAGE`, `G3PDF`, `G3ZIP`, `G3FILEUPLOADER`, `G3STRINGBUILDER`, `G3AXON.FUNCTIONS`. **Exception:** do not use `G3JSON.Parse` in a request that also uses `G3DB` (see section 8); the API controllers use the pure-VBScript `core/lib.JsonLite.asp` instead. |
|
|
- **Prefer native libraries over hand-rolled ASP:** `G3JSON`, `G3DB`, `G3HTTP`, `G3CRYPTO`, `G3MAIL`, `G3FILES`, `G3TEMPLATE`, `G3MD`, `G3IMAGE`, `G3PDF`, `G3ZIP`, `G3FILEUPLOADER`, `G3STRINGBUILDER`, `G3AXON.FUNCTIONS`. **Exception:** do not use `G3JSON.Parse` in a request that also uses `G3DB` (see section 8); the API controllers use the pure-VBScript `core/lib.JsonLite.asp` instead. |
|
|
- `Val()` is not usable in this build (Type mismatch even for "7"). Convert with `CDbl` (mind the locale decimal separator: JSON uses `.`). |
|
|
- `Val()` is not usable in this build (Type mismatch even for "7"). Convert with `CDbl` (mind the locale decimal separator: JSON uses `.`). |
|
|
@@ -113,7 +113,7 @@ Create objects with `Server.CreateObject("ProgID")` using exact ProgIDs from `de |
|
|
|
|
|
|
|
|
## 6. Configuration |
|
|
## 6. Configuration |
|
|
|
|
|
|
|
|
- Server config: `deploy/app/config/axonasp.toml` (copied into the image). Any key can be overridden by an environment variable when `viper_automatic_env = true`: `[server] web_root` -> `SERVER_WEB_ROOT`, `server_port` -> `SERVER_SERVER_PORT`, `[global] default_mslcid` -> `GLOBAL_DEFAULT_MSLCID`, and so on. A different config file: `axonasp-http -c path.toml`. |
|
|
|
|
|
|
|
|
- Server config: `/opt/axonasp/config/axonasp.toml` inside the container (stock image; override with env vars in `docker-compose.yml`). Any key can be overridden by an environment variable when `viper_automatic_env = true`: `[server] web_root` -> `SERVER_WEB_ROOT`, `server_port` -> `SERVER_SERVER_PORT`, `[global] default_mslcid` -> `GLOBAL_DEFAULT_MSLCID`, and so on. A different config file: `axonasp-http -c path.toml`. |
|
|
- **web.config is processed only if `enable_webconfig = true`, only from the web root, and only a subset of IIS** (`rewrite`, `httpRedirect`, `httpErrors`, and appSettings read by app code). Subdirectory web.config files are ignored. |
|
|
- **web.config is processed only if `enable_webconfig = true`, only from the web root, and only a subset of IIS** (`rewrite`, `httpRedirect`, `httpErrors`, and appSettings read by app code). Subdirectory web.config files are ignored. |
|
|
- Rewrite patterns use **Go RE2: no lookahead (`(?!...)`), no backreferences.** **[verified here]** a lookahead rule silently never matched. To exclude static files, use the `IsFile` / `IsDirectory` conditions instead. Supported condition inputs: `{REQUEST_FILENAME}`, `{URL}`, `{REQUEST_URI}`. Rewrites run before ASP execution. After a rewrite the server's `URL` is the rewritten target, so pass the original path in the query string (`__route`), as `public/web.config` does. |
|
|
- Rewrite patterns use **Go RE2: no lookahead (`(?!...)`), no backreferences.** **[verified here]** a lookahead rule silently never matched. To exclude static files, use the `IsFile` / `IsDirectory` conditions instead. Supported condition inputs: `{REQUEST_FILENAME}`, `{URL}`, `{REQUEST_URI}`. Rewrites run before ASP execution. After a rewrite the server's `URL` is the rewritten target, so pass the original path in the query string (`__route`), as `public/web.config` does. |
|
|
- Application settings come from `GetAppSetting("Key")` (reads `web.config` appSettings). Keep secrets out of source control; prefer environment variables for credentials. |
|
|
- Application settings come from `GetAppSetting("Key")` (reads `web.config` appSettings). Keep secrets out of source control; prefer environment variables for credentials. |
|
|
@@ -149,6 +149,10 @@ Create objects with `Server.CreateObject("ProgID")` using exact ProgIDs from `de |
|
|
- **Static files under `public/`** (for example `public/api/*.openapi.json`) are served directly; the rewrite rule skips existing files and directories. Only routes in `public/Default.asp` go through the MVC dispatcher; a route needs the controller in `autoload_controllers.asp` **and** in `ControllerRegistry` (the generators do both). |
|
|
- **Static files under `public/`** (for example `public/api/*.openapi.json`) are served directly; the rewrite rule skips existing files and directories. Only routes in `public/Default.asp` go through the MVC dispatcher; a route needs the controller in `autoload_controllers.asp` **and** in `ControllerRegistry` (the generators do both). |
|
|
- **Swagger UI:** the multi-spec dropdown (`urls: [...]`) only works with `presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset]` and `layout: "StandaloneLayout"`. Without them the page says "No API definition provided". |
|
|
- **Swagger UI:** the multi-spec dropdown (`urls: [...]`) only works with `presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset]` and `layout: "StandaloneLayout"`. Without them the page says "No API definition provided". |
|
|
- **Git Bash:** `curl` sends non-ASCII literals as cp1252, not UTF-8 (use `ü` escapes or a file with `--data-binary @file`); read CSRF tokens from the form with a cookie jar (`-c/-b`); strip `\r` from values printed by Python on Windows before putting them in URLs. |
|
|
- **Git Bash:** `curl` sends non-ASCII literals as cp1252, not UTF-8 (use `ü` escapes or a file with `--data-binary @file`); read CSRF tokens from the form with a cookie jar (`-c/-b`); strip `\r` from values printed by Python on Windows before putting them in URLs. |
|
|
|
|
|
- **Include order matters for class methods.** A class method cannot see a global Function/Class defined in a file included *after* the class's file (`GetRouter()`, `Flash()` failed with "Object required" / "doesn't support this property or method"). `core/autoload_core.asp` therefore includes `mvc.asp` last. |
|
|
|
|
|
- **Dynamic Eval/Execute in classes is unreliable.** `Eval`/`Execute` inside a Class method cannot see global functions; with a runtime-built string they re-emit a method's inline HTML twice (second copy after the footer); `CallByName` is a silent no-op. Do not dispatch with them. |
|
|
|
|
|
- **Call sites bind to the first class.** `CurrentController.Invoke ...` in one place was bound to the first controller's `Invoke` and reused for every later controller (the first dispatched action's body appeared on every route; title/layout were right). Each controller therefore exposes a global `<Name>Controller_Invoke(actionName, args)` and the dispatcher calls it through `GetRef` (`MVC_InvokeAction`). New controllers must define `Invoke` and `<Name>Controller_Invoke` (the generators emit both). |
|
|
|
|
|
- **Single-line `If x Then a = b Else a = c` swallowed the rest of a Sub** under `On Error Resume Next`. Always use multi-line `If`. |
|
|
- **Class member vs local name clash.** Avoid a local `Dim controllerName` inside a class that also has a `ControllerName` property. |
|
|
- **Class member vs local name clash.** Avoid a local `Dim controllerName` inside a class that also has a `ControllerName` property. |
|
|
- **`Empty Is Nothing` raises "Object required".** Test with `IsObject` / `IsEmpty` first, then `Is Nothing`. |
|
|
- **`Empty Is Nothing` raises "Object required".** Test with `IsObject` / `IsEmpty` first, then `Is Nothing`. |
|
|
- **`Server.Execute(file)` runs the file as a separate page.** It does not define procedures in the caller's scope. To load a script's Subs, read the file and `ExecuteGlobal` the text (strip `<%`/`%>`), as the migrator does. |
|
|
- **`Server.Execute(file)` runs the file as a separate page.** It does not define procedures in the caller's scope. To load a script's Subs, read the file and `ExecuteGlobal` the text (strip `<%`/`%>`), as the migrator does. |
|
|
@@ -164,7 +168,7 @@ Create objects with `Server.CreateObject("ProgID")` using exact ProgIDs from `de |
|
|
- Parameterize SQL. Never accept table or column names from users. |
|
|
- Parameterize SQL. Never accept table or column names from users. |
|
|
- `Server.HTMLEncode` all output derived from input, headers, DB data and errors. |
|
|
- `Server.HTMLEncode` all output derived from input, headers, DB data and errors. |
|
|
- Do not show `ASPError` details (file, line, source) to end users in production. Log them instead; custom pages go through `httpErrors` in `web.config`. |
|
|
- Do not show `ASPError` details (file, line, source) to end users in production. Log them instead; custom pages go through `httpErrors` in `web.config`. |
|
|
- Keep `blocked_extensions` / `blocked_dirs` in `axonasp.toml` intact. Do not place secrets, `.sqlite` files or migrations under the web root (`public/`). |
|
|
|
|
|
|
|
|
- Keep `blocked_extensions` / `blocked_dirs` in the container's `axonasp.toml` intact. Do not place secrets, `.sqlite` files or migrations under the web root (`public/`). |
|
|
- Do not enable `allow_external_filesystem_access` unless a trusted need is documented. |
|
|
- Do not enable `allow_external_filesystem_access` unless a trusted need is documented. |
|
|
- Use `G3CRYPTO` for hashing and tokens. Do not roll your own. |
|
|
- Use `G3CRYPTO` for hashing and tokens. Do not roll your own. |
|
|
- The generated JSON APIs are **unauthenticated and have no CSRF protection** (stateless by design). Put authentication in front of them before exposing the app, and keep HTML form posts on the CSRF token (`HTMLSecurity()`). |
|
|
- The generated JSON APIs are **unauthenticated and have no CSRF protection** (stateless by design). Put authentication in front of them before exposing the app, and keep HTML form posts on the CSRF token (`HTMLSecurity()`). |
|
|
@@ -174,7 +178,7 @@ Create objects with `Server.CreateObject("ProgID")` using exact ProgIDs from `de |
|
|
## 10. Working rules for agents in this repo |
|
|
## 10. Working rules for agents in this repo |
|
|
|
|
|
|
|
|
- **Use the provided scripts; do not hand-create what they generate.** New migration -> `scripts\gen.cmd migration`; model + repository -> `scripts\gen.cmd repo`; JSON API (controller, routes, whitelist, includes, OpenAPI spec, `.http` file) -> `scripts\gen.cmd api`; HTML controller stub with routes -> `scripts\gen.cmd controller`; schema changes -> `scripts\migrate.cmd up|down|status`. Edit generated files afterwards (migration bodies, business rules, views), but never write a controller, repository, POBO, route, whitelist entry or migration file from scratch when a generator exists, and never change the schema outside a migration. If a generator is missing a feature or produces something wrong, fix the generator/template in `scripts/` (and say so) instead of patching the output only. |
|
|
- **Use the provided scripts; do not hand-create what they generate.** New migration -> `scripts\gen.cmd migration`; model + repository -> `scripts\gen.cmd repo`; JSON API (controller, routes, whitelist, includes, OpenAPI spec, `.http` file) -> `scripts\gen.cmd api`; HTML controller stub with routes -> `scripts\gen.cmd controller`; schema changes -> `scripts\migrate.cmd up|down|status`. Edit generated files afterwards (migration bodies, business rules, views), but never write a controller, repository, POBO, route, whitelist entry or migration file from scratch when a generator exists, and never change the schema outside a migration. If a generator is missing a feature or produces something wrong, fix the generator/template in `scripts/` (and say so) instead of patching the output only. |
|
|
- **The scripts need Docker.** `gen.cmd` and `migrate.cmd` run `docker exec ... axonasp ./axonasp-cli`, so Docker must be running and the `axonasp` container up (`cd deploy && docker compose up -d`) before using them. If it is not running, start it or tell the user; do not fall back to hand-writing the files. Run them from PowerShell or cmd, not Git Bash. Generators only write files: `docker restart axonasp` afterwards. |
|
|
|
|
|
|
|
|
- **The scripts need Docker.** `gen.cmd` and `migrate.cmd` run `docker exec ... axonasp ./axonasp-cli`, so Docker must be running and the `axonasp` container up (`docker compose up -d` from the repo root) before using them. If it is not running, start it or tell the user; do not fall back to hand-writing the files. Run them from PowerShell or cmd, not Git Bash. Generators only write files: `docker restart axonasp` afterwards. |
|
|
- Make the smallest change that solves the problem. Match the style of the file you are editing. |
|
|
- Make the smallest change that solves the problem. Match the style of the file you are editing. |
|
|
- After changing ASP code, restart the container, then verify in the running app (`curl localhost:8801/...`) before claiming success. Report real output and real errors. |
|
|
- After changing ASP code, restart the container, then verify in the running app (`curl localhost:8801/...`) before claiming success. Report real output and real errors. |
|
|
- Test every new endpoint through the whole range: happy path, validation (422), bad input (400), unknown id (404), wrong method (405), HTML-escaping, UTF-8 round trip, and a cold first request after a restart. JSON APIs: curl, the generated `api-tests/<table>.http` and the Swagger page `/api/docs`. |
|
|
- Test every new endpoint through the whole range: happy path, validation (422), bad input (400), unknown id (404), wrong method (405), HTML-escaping, UTF-8 round trip, and a cold first request after a restart. JSON APIs: curl, the generated `api-tests/<table>.http` and the Swagger page `/api/docs`. |
|
|
@@ -182,5 +186,5 @@ Create objects with `Server.CreateObject("ProgID")` using exact ProgIDs from `de |
|
|
- When a bug does not make sense, stop patching around it: reduce it to a small page, change one variable at a time, and write the finding into section 8. |
|
|
- When a bug does not make sense, stop patching around it: reduce it to a small page, change one variable at a time, and write the finding into section 8. |
|
|
- Do not add `On Error Resume Next` to silence an error. Surface it. |
|
|
- Do not add `On Error Resume Next` to silence an error. Surface it. |
|
|
- Keep new code to the portable subset in section 2 unless the user asks for AxonASP extensions. |
|
|
- Keep new code to the portable subset in section 2 unless the user asks for AxonASP extensions. |
|
|
- Do not modify `deploy/www/` (stock demo and manual) or `deploy/app/` binaries. |
|
|
|
|
|
|
|
|
- Do not modify anything under `/opt/axonasp` in the container except the mounted `site/` folder. |
|
|
- Ask before deleting migrations, the database file, or anything under `db/`. |
|
|
- Ask before deleting migrations, the database file, or anything under `db/`. |