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.
When unsure about an object, ProgID, method or config key, check deploy/www/manual/md before guessing. Do not invent APIs.
asp-classic-unified-framework/ the application (MVC starter, "RouteKit")
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)
app/ controllers/ (HTML: <Name>Controller, JSON: Api<Name>Controller), models/ (POBO_<T>, <T>Repository),
views/<Name>/
db/ app.sqlite (SQLite) and migrations/
scripts/ migrate.cmd/.asp, gen.cmd (generators: migration, repo, controller, api), templates/ (POBO,
Repository, Api). Run through the AxonASP CLI in the container.
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)
cd deploy && docker compose up -d --build -> http://localhost:8801/opt/axonasp/site and sets SERVER_WEB_ROOT=/opt/axonasp/site/public. This keeps ../core, ../app, ../db reachable from public/.scripts\migrate.cmd status|up|down (runs axonasp-cli inside the container).deploy/www/ is the stock AxonASP demo site and manual. It is not part of this app.scripts\gen.cmd migration create_<table>_table, then fill in Migration_Up/Migration_Down by hand (the generator leaves TODOs), then scripts\migrate.cmd up.scripts\gen.cmd api /table:<Table> /pk:Id. One run writes the POBO + repository, Api<Table>Controller.asp, the includes, the controller whitelist entry, six routes under /api/<table>, public/api/<table>.openapi.json (shows up in the /api/docs dropdown) and api-tests/<table>.http. Validation comes from column types and NOT NULL/DEFAULT, CreatedAt/UpdatedAt text/date columns are set by the server, and an existing controller is never overwritten. Business rules (ranges, formats) are added by hand.scripts\gen.cmd controller <Name> Index "Show(id)" NewForm Create "Edit(id)" "Update(id)" "Delete(id)" writes a stub controller and wires it (include, whitelist, routes: Index/NewForm/Create/Show/Edit/Update/Delete get REST routes, any other action gets GET /<name>/<action>/:param). The actions and app/views/<Name>/{index,show,form}.asp are filled in by hand. Pattern used by the (removed) sample CRUD: list with ?q= search and ?page= paging via the repository's SearchTablePaged; forms carry HTMLSecurity().GetAntiCSRFToken(name) as a hidden csrf_token and POST actions check IsValidAntiCSRFToken (failure: flash error + redirect); validation errors re-render the form with status 422; deletes are POSTs; all output goes through Server.HTMLEncode; the layout header is already buffered, so Response.Clear before Response.Redirect. Put Const values outside the class (section 8).docker restart axonasp, then test (section 10). Add a nav link in app/views/shared/header.asp for new HTML pages.gen.cmd controller from PowerShell or cmd, not Git Bash (quotes such as "Show(id)" reach the script literally; the generator strips them now, but cmd quoting is still the reliable path). Generators run inside the container with the framework folder as web root, so they use paths like /public/..., /app/....Option Explicit in every page and include that owns top-level code.If. Always If ... Then / End If.Dim x = 1. No As Type unless deliberately using an AxonASP extension (section 4).Set for every object assignment. Release long-lived objects with Set obj = Nothing.Call name(args). Foo(a, b) as a statement is wrong. Calling a Function and using its result: parentheses required.And/Or. Both sides are always evaluated, so If Not rs.EOF And rs("x") = 1 and If s = "" Or CDbl(s) > 1 both fail. Nest the Ifs. (AndAlso/OrElse are AxonASP extensions; see section 4.)&, never +.= is both assignment and comparison. String = comparison is case-insensitive. _ at end of line. Statements do not wrap otherwise.On Error Resume Next, check Err.Number, then Err.Clear / On Error GoTo 0. Keep the scope of Resume Next small and check errors right after the risky statement. Never use it to hide failures: report the error (number, description, and the SQL or input involved).<%@Language="VBSCRIPT" CodePage="65001"%> on the very first line, compact, one line. Never leave <% or %> unclosed.ByVal when the caller's variable must not change.Server.HTMLEncode(value). Always URL-encode query values: Server.URLEncode.Application writes must be wrapped in Application.Lock / Application.Unlock. Never Response.Redirect or Response.End while locked.Application/Session.<!--#include ... --> is textual and resolved before execution. The path cannot be a variable.file= is relative to the including file and must not use ..; virtual= is relative to the web root and is the preferred form. This project's framework uses file="../core/..." and it works on this build [verified here], but prefer virtual= for anything under the web root, and keep includes that cross out of public/ consistent.../core/ not ../Core/, lib.Collections.asp not lib.collections.asp). Check this whenever you add or move a file.Sub are allowed here (the MVC dispatcher does it) but inject the file text at that spot.Server.MapPath("/x") is relative to the web root. A relative path is relative to the current script's directory. Under the CLI the web root and script directory can differ from the web server; see section 8.Scripting.FileSystemObject is limited to the web root unless server.allow_external_filesystem_access = true in axonasp.toml. Keep new file access inside the web root (or the mounted framework folder when running the CLI with that as root).global.asa lives at the web root. It is compiled at startup; restart to pick up changes. Request/Response are not available in Application events.AxonASP adds VB6/VB.NET-style features. They make code non-portable to IIS, so use them only when the project has chosen AxonASP permanently, and note it in a comment.
AndAlso, OrElse; IsNot; << / >>.On Error GoTo <label>, GoTo, Resume, On Error GoTo -1 (classic VBScript only has Resume Next and GoTo 0).Optional / ParamArray parameters, Static, Enum, Type ... End Type (UDT), Dim x As Type, Implements, Event / RaiseEvent / WithEvents, non-zero array bounds and Option Base.console.log/info/warn/error for diagnostics.Collection object and [DispId(-4)] for-each delegation.The portable rules in section 2 remain the default for framework and application code.
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.
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 .).Scripting.FileSystemObject, Scripting.Dictionary, ADODB.Connection/Recordset/Command/Stream, MSXML2.ServerXMLHTTP, MSXML2.DOMDocument / Microsoft.XMLDOM, VBScript.RegExp, WScript.Shell (environment/exec only), CDO aliases for G3MAIL.G3JSON (outside the DB-request caveat above), file upload -> G3FILEUPLOADER, email -> G3MAIL, password hashing and GUIDs -> G3CRYPTO (HashPassword/VerifyPassword use bcrypt, UUID())..wsc, GetObject("script:...")), the WScript host object, cscript/WSH scripts, regsvr32 COM, Access-only SQL.CreateObject and will fail on Linux. Verify a ProgID in the manual before using it.Request.ServerVariables("HTTP_X_ORIGINAL_URL") is an IIS URL Rewrite header and is empty here. Use GetRequestPath() from core/helpers.asp..accdb/.mdb, Jet/ACE) is Windows-only and is not supported in the Linux container.core/lib.Data.asp, DAL()) runs on G3DB. ConnectionString in public/web.config is <driver>:<dsn>, currently sqlite:/opt/axonasp/site/db/app.sqlite. Use DAL().Query(sql, params) (result set), DAL().Exec(sql, params) (returns RowsAffected/LastInsertId), DAL().Execute, PagedQuery(sql, params, per_page, page) (LIMIT/OFFSET), and BeginTransaction/CommitTransaction/RollbackTransaction. params is Empty, one value, or an array (max 8). Failures raise a VBScript error that includes the SQL.EOF, MoveNext, rs("col"), rs(0), Fields.Count, GetRows, Close. They do not expose column names (Fields(i).Name fails), so anything that needs names must select explicit, aliased columns. G3DB does not expand an array into parameters and gives no driver error text for statements inside a transaction.G3DB is the preferred native API for new code: db.Open("sqlite", path), db.Query(sql, params...), db.Exec(sql, params...), db.Begin(). It returns Empty on failure and reports via db.LastError.TOP n (use LIMIT n), no #date# literals (use ISO 'YYYY-MM-DD HH:MM:SS' text), INTEGER PRIMARY KEY AUTOINCREMENT, DROP INDEX name (no ON table). ALTER TABLE ... DROP COLUMN needs SQLite 3.35+.? parameters for user input. [verified here] the old ADODB Command.Execute(, Array(...)) path failed with “missing argument with index 1”; G3DB parameters work.app.sqlite.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.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.(?!...)), 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.GetAppSetting("Key") (reads web.config appSettings). Keep secrets out of source control; prefer environment variables for credentials.Session.LCID (default global.default_mslcid). Set it explicitly before FormatDateTime, FormatNumber, FormatCurrency.db/migrations/ and are named YYYYMMDDHHMMSS_description.asp (14-digit version). Each defines Migration_Up(migration) and Migration_Down(migration).migration: ExecuteSQL, CreateTable, DropTable, AddColumn, DropColumn, CreateIndex, DropIndex.scripts\migrate.cmd status, up, down (one step). The runner is scripts/migrate.asp using Migrator_Class in core/lib.Migrations.asp.On Error Resume Next there.CLng (overflow); use CDbl or compare strings.bytecode_caching_enabled in [global]). During development, if an edit seems ignored or an error line number does not match the file, run docker restart axonasp (or set GLOBAL_BYTECODE_CACHING_ENABLED=disabled) before debugging further.Response.Write markers rather than trusting the line.MVC.DispatchRequest a, b (where MVC is a Function returning an object) failed with “Object required”. Use MVC().DispatchRequest a, b, or assign to a variable first: Set m = MVC(). The same applies to router, Flash, Routes, DAL, and any singleton accessor. Expression form (x = MVC.Prop, TypeName(MVC)) works.put is parsed as the file Put #n statement and breaks put "text". Do not name Subs/Functions after VB statements (Put, Get, Open, Close, Print, Input, Seek, Lock, Name, Kill, ...). The framework's output helper is now puts / puts_.Const is Empty. Private Const X = 10 inside a Class evaluates to Empty in methods (no error, so e.g. per_page silently became 0 and paging broke). Declare Const at top level, outside the class, with a prefixed name.G3JSON.Parse before the first database open in the process made the first INSERT silently do nothing (201 with id 0, no row), and only on the first POST after a restart; opening the database first made Parse return dictionaries whose Exists/Item returned stale values. Dictionaries built in a Function and returned also came back empty, and the first native call after another native call could return the previous value. For API controllers use core/lib.JsonLite.asp (pure VBScript: JsonLite_Parse -> object with .Exists(k)/.Item(k) (call .Item, there is no default member), JsonLite_Quote, JsonLite_Num) and compose output JSON as text. Plain VBScript classes are safe; native objects held across other native calls are not.Request.BinaryRead(n) returns one character per byte (raw UTF-8 bytes), not decoded text. Decode UTF-8 yourself (Utf8Decode in the API controllers, which maps invalid bytes to U+FFFD); ADODB.Stream was unreliable too. MSXML2.ServerXMLHTTP works in the CLI for calling the local server, which is a handy way to write an HTTP smoke test (axonasp-cli -r script.asp inside the container, base URL http://localhost:8801).Dispatch/ExecuteControllerAction in core/mvc.asp run under On Error Resume Next, so an error inside an action aborts it and the response is an empty 200 (or a half page) with no message. For write paths wrap the DB call in a local On Error Resume Next, check Err.Number straight after it and answer with a real error (the API controllers send a JSON 500 via DbFailed). When something “does nothing”, test the same code from a plain page or the CLI to see the real error.docker restart axonasp, send the write request (POST/PUT/DELETE) first, before any GET: some bugs only appear on the first request after a start. Debugging aid: Response.Clear wipes the body, but Response.AddHeader "X-Dbg-1", "..." survives, so trace with headers (curl -i). When patching with scripts, assert that each replacement matched (a silent no-op edit cost hours here)."ok=" & Not (x Is Nothing) raises Type mismatch. Put the Not ... in a variable first.Response.Clear before Response.Redirect, and for non-HTML actions set useLayout to False (the API controllers do).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).urls: [...]) only works with presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset] and layout: "StandaloneLayout". Without them the page says “No API definition provided”.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.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.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.axonasp-cli -r file.asp runs ASP; -m vbscript runs pure .vbs (no WScript). The CLI's web root comes from config (SERVER_WEB_ROOT), Server.MapPath is relative to the script's folder, relative .. is clamped to the web root, and FileSystemObject cannot leave the web root. Run CLI tools with -e SERVER_WEB_ROOT=<framework folder> and use Server.MapPath("/...")./opt/... arguments passed to docker exec. Prefix with MSYS_NO_PATHCONV=1, or run from cmd/PowerShell.db/app.sqlite) are owned by root inside the container; this is fine on Windows hosts.Execute/Eval dispatch (the registry in core/lib.ControllerRegistry.asp does this). Never build code or SQL from raw request input.Server.HTMLEncode all output derived from input, headers, DB data and errors.ASPError details (file, line, source) to end users in production. Log them instead; custom pages go through httpErrors in web.config.blocked_extensions / blocked_dirs in axonasp.toml intact. Do not place secrets, .sqlite files or migrations under the web root (public/).allow_external_filesystem_access unless a trusted need is documented.G3CRYPTO for hashing and tokens. Do not roll your own.HTMLSecurity()).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.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.curl localhost:8801/...) before claiming success. Report real output and real errors.api-tests/<table>.http and the Swagger page /api/docs.migrate.cmd down first), and leave the database as you found it.On Error Resume Next to silence an error. Surface it.deploy/www/ (stock demo and manual) or deploy/app/ binaries.db/.Powered by TurnKey Linux.