The simplest URL mapping is the class method that uses Tiwappform: SetUrl;
Thandlers is the new content processor of Intraweb XIV, which can do more than just URL mapping.
Thandlers can go to or process any file via virtual path, virtual file name.
This process will use a tcontentbase type of parameters, Tcontentform, Tcontentredirect is its sub-class; It is sometimes necessary to inherit from Tcontentbase subclasses that solve more problems.
thandlersUnit and succession chain:
IW. Content.Handlers.THandlers < TObject
Main members:
{Add to Content Processor: Apath: virtual path; adocument: virtual folder name; Ahandler: content to add}class function add (const apath:string; const Adocument:strin G Ahandler:tcontentbase): Tcontentbaseclass function Add (const adocument:string; ahandler:tcontentbase): TContentBase{ Add first page}class function addstarthandler (const apath:string; const adocument:string; ahandler:tcontentbase): Tcontentbaseclass function Getstarthandler (asession:tiwapplication): tcontentbase{add uniform processing}class function for the specified extension Addforextension (const aext:string; ahandler:tcontentbase): Tcontentbaseclass function Findmatch (afullpath:string): Tcontentbaseclass procedure Registergetstarthandlerproc (Aproc:tgetstarthandlerproc = procedure (asession: Tiwapplication; var ahandler:tcontentbase) of object)
The Tiwappform.seturl method should be used in the initialization section, such as:
{If there are three forms, this is part of the code for UNIT1:}//...procedure Tiwform1.iwbutton1click (sender:tobject); Begin Webapplication.gotourl ( ' bbb.aspx ');// Webapplication.gotourl (' abc/ccc.xxx '); end;initialization Tiwform1.setasmainform; Tiwform1.seturl (', ' aaa.html '); Parameter 1 is the virtual path, ' or '/' indicates the root path; The parameter 2 is the virtual file name end. {This is part of the code for UNIT2:-------------------------------------------}//...initialization tiwform2.seturl ('/', ' bbb.php ‘); The name is virtual, not the real php file end. {This is part of the code for UNIT3:-------------------------------------------}//...initialization tiwform3.seturl ('/abc/', ' Ccc.xxx '); end. {By setting above, the above three forms correspond to the following three URLs (assuming the test address is: 127.0.0.1:8888)}http://127.0.0.1:8888/aaa.htmlhttp://127.0.0.1:8888/ Bbb.phphttp://127.0.0.1:8888/abc/ccc.xxx
Thandlers Test One:
{The code is written mainly in the Iwservercontroller OnConfig event, the following is part of the code:}uses iwinit, Iwglobal, Unit1, Unit2, Unit3, {unit1-3 corresponds to three forms}
iw. Content.handlers, IW. Content.base, IW. Content.form, IW. Content.redirect; {thandlers, tcontentbase, Tcontentform, tcontentredirect units required separately} {Iwservercontrollerbase.onconfig event; Before I was tested in OnCreate, the official recommendation is that the code should be in the OnConfig event}procedure Tiwservercontroller.iwservercontrollerbaseconfig (sender:tobject); Begin Thandlers.add ("', ' aaa.htm ', Tcontentform.create (TIWForm1)); Thandlers.addstarthandler (', ' bbb.htm ', Tcontentform.create (TIWForm2)); Purely experimental, set TIWFORM2 home page thandlers.addforextension ('. php ', tcontentform.create (TIWFORM3)); Just visit *.php's page and go to TIWForm3 thandlers.add (', ' ccc.htm ', tcontentredirect.create (' xxx.html ')); Xxx.html, then visit ccc.htm can go to xxx.htmlend;
Thandlers Test Two: On the custom tcontentbase, the official gives such an example:
{Custom Tcontentxml cells:-----------------------------------------------------------}unit myxml;interfaceuses Classes, IW. Content.base, Httpapp, Iwapplication, IW. HTTP. Request, IW. HTTP. Reply;type Tcontentxml = Class (Tcontentbase) protected function Execute (arequest:thttprequest; areply:thttpreply; c Onst apathname:string; Asession:tiwapplication; aparams:tstrings): Boolean; Override Public constructor Create; Override End;implementationuses IW. Content.handlers, Iwmimetypes;constructor Tcontentxml.create;begin inherited; Mfilemustexist: = False;end;function tcontentxml.execute (arequest:thttprequest; areply:thttpreply; Const APathname: String Asession:tiwapplication; aparams:tstrings): Boolean;begin Result: = True; If Assigned (areply) THEN begin areply.contenttype: = Mime_xml; Areply.writestring (' <xml>my XML Content here</xml> '); End;end;end. {Part of the relevant code for the Servercontroller unit:--------------------------------------------------}uses iwinit, Iwglobal, IW. Content.handlers, myXML; {Iwservercontrollerbase.onconfig event}procedure tiwservercontroller.iwservercontrollerbaseconfig (Sender:tobject); Begin Thandlers.add (', ' XmlTest ', tcontentxml.create); end; {Some related code for the UNIT1 unit:-------------------------------------------------------------}procedure Tiwform1.iwbutton1click (sender:tobject); Begin Webapplication.gotourl (' XmlTest '); end;