%Response Example: Redirection
Complete the following steps to use redirection with %response and its Redirect property.
-
Add the following script to the <Body> section of StateTest.csp while leaving the existing code unchanged. The script defines the onPreHTTP method for the page. The method tests the value of the password entered into SignIn.CSP. If the value is not “CSP” the method redirects the user to Error.CSP (See the note below for the location of this file). Otherwise, StateTest.CSP loads. Note that onPreHTTP returns 1. If it returned 0, then StateTest.CSP would not load.
<script language="cache" method="OnPreHTTP" arguments="" returntype="%Boolean"> if ($Get(%request.Data("txtPassword",1)) '= "CSP") { set %response.Redirect="Error.CSP" } quit 1 </script>
-
Open SignIn.CSP in a Web Browser. Enter text other than “CSP” into the password field.
-
Click SignIn. The browser is redirected to Error.CSP
-
Open SignIn.CSP in a Web Browser. Enter “CSP” into the password field.
-
Click SignIn. StateTest.CSP loads into the browser.
Error.CSP is one of the example files that accompany the tutorial. For information on installing the example files, read Installing Tutorial Files.