Class wwProcess

Handling requests and serving as the developer's entry point for Web requests. Most of your Web interface coding will occur at this class level.

The wwProcess class is the heart of Web Connection from the developer's point of view. This class serves as your code entry point where custom logic occurs. Each request in your Web application maps to a method in a wwProcess subclass. To add new functionality you simply add a method to your implementation of the process class. The simplest implementation looks like this:

*************************************************************
DEFINE CLASS YourProcess AS WWC_PROCESS
*************************************************************

*********************************************************************
FUNCTION HelloWorld()
*********************

THIS.StandardPage("Hello World from the " + THIS.Class + "  process",;
                  "If you got here, everything should be working fine. The time is: " + TIME())
                  
ENDFUNC
* EOF HelloWorld

*********************************************************************
FUNCTION QuickData()
********************

IF !USED('tt_cust')
   USE (THIS.cAppStartPath + "tt_cust")
ENDIF

Response.HTMLHeader("Customer List")
Response.Write("Filename: " + DBF() )
Response.ShowCursor()
Response.HTMLFooter()

ENDFUNC

ENDDEFINE

which can be accessed with a URL like this:

Full Url Syntax

wc.wc?YourProcess~HelloWorld

Script Map syntax(where wc.dll is mapped to .YP)

HelloWorld.yp

Each additional method you add can be referenced in the same manner. Note that in the above StandardPage() is quick method that creates a fully self contained HTML page. For a more customized page you can use the wwResponse object (THIS.oResponse.Write() for example) to create programmatic output or expand template/script pages using the ExpandTemplate/ExpandScript methods of the wwResponse object.

The easiest way to create a new process class is to use the New Process Wizard from the Web Connection Management Console, which hooks up new process entries to the mainline and creates a skeleton class that you can simply start adding methods to.

Exposed generic objects

wwProcess exposes several objects as PRIVATE variables for easier reference:
  • Request
    This object is mapped to wwProcess::oRequest.

  • Response
    This object is mapped to wwProcess::oResponse

  • Server
    This object is mapped to wwProcess::oServer

  • Process
    The wwProcess object that is running the current request. In code this would be referenced as THIS, but in script and templates that value is not valid - use Process instead.

  • Session
    The wwSession object if you created one. This maps to wwProcess::oSession, and is only valid if you either call InitSession or manually create a session and assign it to this property. Otherwise the value is .NULL..

These objects are available everywhere in your applications since they sit at the top of the call stack when your code gets called. This means these objects are in scope in your request methods, as well as further down in your business objects. They are also in scope in in Script and Template files where you can do things like the following:

<%= Request.GetBrowser() %>

Class Members

MemberDescription

OnAuthenticated

Event called after a user has been authenticated. Use this method to retrieve values from Session() and store to process properties.

OnAuthenticateUser

This method/event is called when a user actually logs in with a username and password.

OnCheckForAuthentication

Checks to see if a user is logged in when running in UserSecurity authentication mode.

OnError

Occurs when an error occurs in the Web Connection Process handling and Server.lDebugMode is set to .T.

OnLogout

Hook method that is called after a user has been logged out with a call to Authenticate("LOGOUT").

OnProcessComplete

This event is fired after the request processing has completed, but before the Process object is disposed and the response is sent back to the client.

OnProcessInit

The OnProcessInit method is a hook that can be used to initialize a process class. Here you can create custom objects, run additional configuration tasks that apply to every request that hits this process class.

OnRouting

This method allows you to add a custom route condition into your process class. It makes it possible to apply custom rules for method or page routing that overrides the default behavior that maps to a Process method or Script page.

OnShowAuthenticationForm

Event that is fired when an authentication form should be displayed to prompt for login information. Hook this method to override the behavior of the user interface.

OnUrlRewrite

Use this method if you're using URL rewriting to create extensionless URLs. This method can intercept request routing and take action based on the extensionless path segments.

OnWebSocket

Allows you to interact with Web Connection Web Sockets using a custom hybrid message protocol. This method lets you handle Web Socket messages from clients by accessing the loSocket.oMessage parameter, updating the message and broadcasting a new message to connected Web Sockets optionally.

AddAntiForgeryToken

Creates an anti-forgery token that prevents cross site scripting attacks.

o.AddAntiForgeryToken(llAsHtml)

Authenticate

Authenticates a user based on the Authentication method specified in the cAuthentionMode. The method handles the entire Web process of Authentication and tracking a user via a Session (with an HTTP Cookie). Authentication modes supported are Basic, UserSecurity or . UserSecurity uses the wwUserSecurity class for authentication. Custom requires overriding the OnAuthenticateUser method which allows a custom authentication business process. The default is Basic which uses HTTP Basic Authentication.

o.Authenticate(lcUserName,lcErrorMessage,llNoForcedLogin)

CaptchaImage

Dual purpose function that is used to set a CAPTCHA image and then also serve the image to the client. CAPTCHA can be used to validate a request and ensure that a user enters the data as opposed to a robot or HTTP client to minimize SPAMming any form entries.

o.CaptchaImage(lcText,lcFont,lnFontSize)

CheckAntiForgeryToken

Used to check an AntiForgeryToken injected into the page via AddAntiForgeryToken().

o.CheckAntiForgeryToken(lnTimeoutSeconds)

ErrorMsg

This method is a simple way to create a fully self contained HTML page with just a couple of lines of code. This is great for testing output or error messages that let the user know of certain problems with the application.

o.ErrorMsg(lcHeader, lcBody, lvHeader, lnRefresh, lcRefreshUrl, lcIcon)

GetAppSetting

Returns a setting from the application's INI file.

o.GetAppSetting(lcKey,lcSection)

GetUrlBasePath

Retrieves the virtual path of the current request. The value is provided with leading and trailing forward slashes. This path is used to resolve paths for ResolveUrl().

o.GetUrlBasePath()

GetWCIniSetting

This method can be used to read values from the wc.ini file.

o.GetWCIniSetting(lcKey,lcSection)

GetWebResourceUrl

Returns a URL to retrieve a Web Resource that is embedded in the application or served by the application dynamically. The URL can be used to embed the resource into the page.

o.GetWebResourceUrl(lcResourceKey)

InitSession

Sessions are used to keep a server side session for a particular user. They use a Cookie to track the user, and a database record to store any data you attach to the session. Sessions have a timeout when they expire and the expiration lease is renewed each time the session is accessed.

o.InitSession(lcSessionCookieName, lnTimeoutSeconds, llPersist, llSecure)

LogError

Method that is used to log an error into the Web Connection Error Log. This method should be called from the OnError event of this class.

o.LogError(loException)

PageFooterTemplate

Renders a default footer template that is found in Views\_PageFooterTemplate.html.

o.PageFooterTemplate(lcTemplatePath)

PageHeaderTemplate

Renders a standard page header based on the default header template located in Views\_PageHeaderTemplate.html.

o.PageHeaderTemplate(lcTitle, lcTemplatePath)

PageTemplate

Renders a complete page template into which you can embed HTML template. It uses the template stored at Views\_PageTemplate.html to render the default template and you can customize this template

o.PageTemplate(lcTitle,lcContent,lcTemplatePath)

Process

Use of this method is deprecated. You should use OnProcessInit instead.

o.Process()

ReleaseSession

Releases the specified session by removing expiring and clearing the session cookie and deleting the session record.

o.ReleaseSession(lcSessionId)

ResolvePath

Resolves ~/ in a URL like ~/page.wc or ~/subfolder/page.wc to a site relative path like /wconnect/page.wc or /wconnect/subfolder.wc.

o.ResolvePath(lcPath)

ResolveServerUrl

Resolves a virtual path that includes ~ at the beginning to a fully qualified HTTP url.

o.ResolveServerUrl(lcVirtualUrl, lcPrefix)

ResolveUrl

This method resolves a Url that starts with a generic ~/ prefix and replaces this with the base virtual path of the application.

o.ResolveUrl()

SendAdminEmail

Sends an email using the configured Email settings in <yourApp>.ini file.

o.SendAdminEmail(lcTitle,lcMessage, lcRecipients,lcSender, llHtml,llAsync, @lcRefErrorMessage)

SendErrorEmail

This method sends email to the assigned administrator that is configured in the Web Connection configuration in app.ini. Specifically it uses the various AdminEmail* values in the configuration to configure mail server, authentication and sender information. Emails are sent only if Adminsenderroremail=On.

o.SendErrorEmail(lcSubject, lcMessage, lcRecipient, lcSender, llForce)

StandardPage

This method is identical in behavior to the ErrorMsg() method and the default implementation simply calls back to the ErrorMsg() method. Please see the documentation for this method. The main reason for both methods is to provide one error message and one status message page separately.

o.StandardPage(lcHeader, lcBody, lvHeader, lnRefresh, lcRefreshUrl,lcIcon)

WebResource

Generic output method can be used to serve embedded resources like related image, css, javascript or other files through the application

o.WebResource()

cAuthenticatedName

When authenticated holds the users display name.

cAuthenticatedUser

The authenticated user id after the user has been authenticated by either a success call to Authenticate() or OnCheckForAuthentication().

cAuthenticationMode

The method used to authenticate requests. Supported methods: Basic, UserSecurity, Custom

cAuthenticationUserMessage

Message displayed on the Authentication dialog for the user when cAuthenticationMode is UserSecurity.

cAuthenticationUserSecurityClass

The class used for Authentication when the cAuthenticationMode is set to UserSecurity.

cAuthenticationUserSecurityKey

The session key that is used to hold the UserSecurity authentication value.

cErrorTemplate

This method allows overriding the default error display page using a template page called through ExpandTemplate. If set specifies a full physical disk path to a page that is used for ErrorMsg and StandardPage output.

cMethodExecutionExclusions

Allows exluding of class methods that are executed as methods on the process class. This allows executing of script pages even if a matching method exists on the wwProcess subclass.

cSessionKey

The name of the Session Cookie used for this application. This is the default Session value.

cUrlBasePath

The Web Application Virtual Path that marks the base path of this application. This path is used internally by ResolveUrl() to define the base path for a URL and the resolving of the ~ character in a path.

lEnableSessionState

Turns on Session Handling for this request.

lIsAuthenticated

Determines if the current user has been authenticated after a call to Authenticate() or OnCheckForAuthentication().

lShowRequestData

Flag that when set causes the current request data - Form Variables, ServerVariables, Session Vars - to be displayed at the end of the current request.

nAuthenticationTimeoutSeconds

Specifies the Session timeout in minutes when you check the Remember Me checkbox on the authentication dialog. The default is 5 days.

nPageScriptMode

Determines the script mode used when a matching method is not found in the class.

oConfig

The oConfig member maps to the server's configuration object for this project.

oRequest

Object reference to a ready to use wwRequest object, which is used for all inputs of your application. This object is preset by the Init method of this class. When Process or your custom methods get control the oRequest object is already set.

oResponse

Object reference to a ready to use wwResponse object, which is used for all HTTP output. This object is preset by the Init method of this class. When Process or your custom methods get control the oResponse object is already set.

oServer

Object reference to a ready to use wwServer object, which is passed down from the wwServer Process method which calls into your wwProcess subclass. This object is preset by the Init method of this class. When Process or your custom methods get control the oServer object is already set.

oSession

If you use the InitSession() method the oSession object will be loaded for you during the call to that method. Once loaded you can access the oSession object to retrieve and store session variables.

oUser

If a request Authenticated using cAuthenticationMode of UserSecurity you can access the User Security's

oUserSecurity

If a request Authenticated using cAuthenticationMode of UserSecurity you can access the user security object directly from here, with the appropriate user selected.

Requirements

Assembly: wwProcess.prg

See also:

Class wwProcess | New Process Wizard

© West Wind Technologies, 1996-2024 • Updated: 01/01/16
Comment or report problem with topic