Cross-site remote form redirect¶
This is the only operation exposed by SAIF.Services.Web. It gives an ASP.NET page or handler a way to forward the current user's browser, together with a set of POST-body name/value parameters, to another URL — for example a payment gateway or another SAIF web application — where a plain HTTP redirect (a GET) cannot carry the required data. The class accumulates the caller's inputs, writes a minimal self-submitting HTML <form> directly to the current response, and ends the response so the browser executes the auto-submit and issues the outbound POST.
| Field | Value |
|---|---|
| Operation ID | OP-SW-01 |
| Trigger | Caller instantiates RemotePost, sets URL, calls AddInput for each parameter, optionally sets FormName, then calls Post() |
| Inputs | Target URL (string), one or more Name/Value pairs added via AddInput, optional FormName (defaults to "form1") |
| Outputs | An HTML response written to the current ASP.NET response containing a hidden <form> that auto-submits via a <body onload> handler; the current response is cleared and ended as part of this operation |
| Primary components | RemotePost (AddInput, URL, FormName, Post) |
| Entry point | Services\SAIF.Services.Web\RemotePost.vb |
Steps¶
- Caller instantiates
RemotePost. The instance starts with an empty internalNameValueCollectionof inputs and a defaultFormNameof"form1". - Caller sets the
URLproperty to the destination address that the auto-submitted form will POST to. - If
URLis never set, it remainsNothing/empty, and the generated form'sactionattribute is written as an empty string, causing the browser to POST back to the current page instead of an external target.* - Caller calls
AddInput(Name, Value)once for each parameter to be sent as a hidden form field. Each call adds an entry to the internalNameValueCollection; the collection allows duplicateNamekeys, so callingAddInputtwice with the same name accumulates rather than replaces the value.* - Caller optionally sets
FormNameto override the default"form1", which changes both the form'snameattribute and thedocument.<FormName>.submit()call emitted in theonloadhandler. - Caller calls
Post(), which performs the remainder of this operation againstHttpContext.Current. - On failure: if
Post()executes outside an active ASP.NET web request (i.e.,HttpContext.Currentis null), aNullReferenceExceptionoccurs when the method dereferencesHttpContext.Current.Response.* Post()callsHttpContext.Current.Response.Clear(), discarding any response content buffered before this call.Post()writes the opening<html><head>markup, then closes the head and opens<body>with anonload="document.<FormName>.submit()"attribute.Post()writes a<form>element withname="<FormName>",method="post", andaction="<URL>".Post()iterates every key in the internal inputs collection and writes one hidden<input name="<Key>" type="hidden" value="<Value>">element per entry, in the collection's enumeration order.- Caller-supplied
NameandValuestrings are written directly into the HTML attribute values viaString.Formatwith no HTML-encoding; values containing quote characters or HTML-significant characters can produce malformed markup or, if the values originate from untrusted input, enable HTML/script injection.* Post()writes the closing</form>and</body></html>tags.Post()callsHttpContext.Current.Response.End(), which flushes the written HTML to the client and terminates further processing of the current request.- The browser receives the HTML page; because scripting is enabled, the
<body onload>handler fires and submits the form, issuing an HTTP POST containing all registered name/value pairs to the targetURL.- If the browser has JavaScript disabled, the
onloadhandler never fires and the auto-submit does not occur, leaving the user on the intermediate blank page with no visible fallback submit control.*
- If the browser has JavaScript disabled, the
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([Caller constructs RemotePost]) --> SetUrl[Set URL property]
SetUrl --> AddInputs[Call AddInput for<br>each name/value pair]
AddInputs --> OptFormName{Override<br>FormName?}
OptFormName -->|Yes| SetFormName[Set FormName property]
OptFormName -->|No| CallPost[Call Post]
SetFormName --> CallPost
CallPost --> HasContext{HttpContext.Current<br>available?}
HasContext -->|No| Err([NullReferenceException])
HasContext -->|Yes| Clear[Response.Clear]
Clear --> Write[Write hidden form with<br>one input per name/value pair]
Write --> End[Response.End]
End --> Browser[Browser receives HTML]
Browser --> JsCheck{JavaScript<br>enabled?}
JsCheck -->|Yes| AutoSubmit([onload fires;<br>browser POSTs to target URL])
JsCheck -->|No| Stuck([Form never submits;<br>user stuck on blank page])
Failure and edge-case behavior¶
- If
Post()is called outside an active ASP.NET web request context (i.e.,HttpContext.Currentis null), aNullReferenceExceptionoccurs at runtime.* - If
URLis not set before callingPost(), the generated form targets an emptyactionattribute, causing the browser to POST back to the current page rather than an external target.* - Caller-supplied
Name/Valuepairs are written directly into HTML<input>attribute values without HTML-encoding; values containing HTML-special characters may produce malformed markup or enable injection if untrusted input is passed.* - Duplicate
AddInputcalls with the sameNameaccumulate multiple values under that key in the underlyingNameValueCollectionrather than overwriting the prior value, and all are written as separate hidden inputs with the samenameattribute.* - If the browser has JavaScript disabled, the
onloadauto-submit never fires and the request is never forwarded to the target URL, with no visible fallback for the user.* Response.End()terminates the current request pipeline; any code after thePost()call in the caller's page lifecycle does not execute for the current request.*
Related documentation¶
Note: Statements marked with
*were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Sources¶
Services\SAIF.Services.Web\RemotePost.vb