<% ' AxonASP: Eval/Execute inside a Class method cannot see global functions, so this ' global helper does the controller lookup on behalf of MVC_Dispatcher_Class. Function MVC_GetController(controllerName) Set MVC_GetController = Eval(controllerName & "()") End Function ' Calls _Invoke(actionName, args), defined at the bottom of each controller file. Sub MVC_InvokeAction(controllerName, actionName, args) Obs_Action = controllerName & "." & actionName Dim entry : Set entry = GetRef(controllerName & "_Invoke") entry actionName, args End Sub ' Set cache expiration from configuration Dim cacheYear : cacheYear = GetAppSetting("CacheExpirationYear") If cacheYear = "nothing" Then cacheYear = "2030" Response.ExpiresAbsolute = "01/01/" & cacheYear Response.AddHeader "pragma", "no-cache" Response.AddHeader "cache-control", "private, no-cache, must-revalidate" '======================================================================================================================= ' MVC Dispatcher '======================================================================================================================= Class MVC_Dispatcher_Class dim CurrentController Public Property Get ControllerName ControllerName = CurrentController end Property '--------------------------------------------------------------------------------------------------------------------- ' Convenience method to resolve route and dispatch in one call ' method: HTTP method (GET, POST, etc.) ' path: Request path (already cleaned of query params) '--------------------------------------------------------------------------------------------------------------------- Public Sub DispatchRequest(method, path) Dim routeArray routeArray = GetRouter().Resolve(method, path) Dispatch routeArray End Sub '--------------------------------------------------------------------------------------------------------------------- ' Main dispatch method - executes a resolved route ' RouteArray: Array(controller, action, params) from GetRouter().Resolve() '--------------------------------------------------------------------------------------------------------------------- Public Sub Dispatch(RouteArray) On Error Resume Next Dim controllerName, actionName, hasParams, paramsArray controllerName = RouteArray(0) actionName = RouteArray(1) ' Security: Validate controller and action names If Not ControllerRegistry.IsValidControllerFormat(controllerName) Then Response.Write "
" Response.Write "Security Error: Invalid controller name format." Response.Write "
" Exit Sub End If If Not ControllerRegistry.IsValidActionFormat(actionName) Then Response.Write "
" Response.Write "Security Error: Invalid action name format." Response.Write "
" Exit Sub End If ' Security: Check controller whitelist If Not ControllerRegistry.IsValidController(controllerName) Then Response.Write "
" Response.Write "Security Error: Controller '" & Server.HTMLEncode(controllerName) & "' is not registered." Response.Write "
" Exit Sub End If ' Initialize current controller Set CurrentController = MVC_GetController(controllerName) ' Check if layout should be used hasParams = (UBound(RouteArray) >= 2) If CurrentController.useLayout Then %> <% End If ' Prepare parameters If hasParams Then paramsArray = RouteArray(2) Else paramsArray = Empty End If ' Execute controller action ExecuteControllerAction controllerName, actionName, paramsArray ' Include footer if layout is used If CurrentController.useLayout Then %> <% End If On Error GoTo 0 End Sub ' Helper method to execute controller actions (eliminates code duplication) Private Sub ExecuteControllerAction(controllerName, actionName, paramsArray) On Error Resume Next Dim actionArgs If IsArray(paramsArray) Then actionArgs = paramsArray Else actionArgs = Array() End If ' Execute the action (static dispatch through the controller's Invoke method) MVC_InvokeAction controllerName, actionName, actionArgs ' Handle errors If Err.Number <> 0 Then HandleDispatchError actionName, Err.Description, Err.Number Err.Clear End If On Error GoTo 0 End Sub ' Centralized error handling for dispatch errors Private Sub HandleDispatchError(actionName, errorDesc, errorNum) Dim isDevelopment isDevelopment = (LCase(GetAppSetting("Environment")) = "development") If isDevelopment Then Response.Write "
" Response.Write "Controller Action Error
" Response.Write "Action: " & Server.HTMLEncode(actionName) & "
" Response.Write "Error: " & Server.HTMLEncode(errorDesc) & "
" Response.Write "Error Number: " & errorNum Response.Write "
" Else Response.Write "
" Response.Write "An error occurred
" Response.Write "Please contact the system administrator if the problem persists." Response.Write "
" End If End Sub Public Sub RequirePost If Request.Form.Count = 0 Then MVC.RedirectToExt "NotValid","",empty:End If End Sub ' Shortcut for RedirectToActionExt that does not require passing a parameters argument. Public Sub RedirectToAction(ByVal action_name) RedirectToActionExt action_name, empty End Sub Public Sub RedirectTo(controller_name, action_name) RedirectToExt controller_name, action_name, empty End Sub ' Redirects the browser to the specified action on the specified controller with the specified querystring parameters. ' params is a KVArray of querystring parameters. Public Sub RedirectToExt(controller_name, action_name, params) Response.Redirect Routes.UrlTo(controller_name, action_name, params) End Sub Public Sub RedirectToActionExt(ByVal action_name, ByVal params) RedirectToExt ControllerName, action_name, params End Sub End Class dim MVC_Dispatcher_Class__Singleton Function MVC() if IsEmpty(MVC_Dispatcher_Class__Singleton) then set MVC_Dispatcher_Class__Singleton = new MVC_Dispatcher_Class end if set MVC = MVC_Dispatcher_Class__Singleton End Function %>