Redirect Method

Advises the browser that the requested page now resides in a different location. As a result, following the current request the browser will load the new page. Therefore, Response.Redirect() allows you to implement re-directions.

Syntax

Response.Redirect( cLocation )

Parameter

cLocation

States the URL of the page to be called by the browser. The browser treats this URL like a link in a document. If no directory is specified, the page will be loaded relative to the current directory. You may however use Response.Redirect() to refer the browser to pages in a different directory or on another server. Even forwarding to pages of other server products like PHP or ASP.NET is possible.

Since this is a new URL that is requested by the browser, the same conditions apply with regard to the session ID as they would with regular links. If the current session is to be continued in the new page, you need to use Session.Url():

<%

  Response.Redirect( Session.Url("newpage.afp") )

%>

As with conventional links you can also transmit parameters to the calling page:

<%

  Response.Redirect( Session.Url("cart.afp","step=checkout&pay=creditcard") )

%>

Note

Response.Redirect generates a HTTP 302 message directing the browser to call the transmitted page. It is important to note that the forwarding is not effected by the server but rather by the browser, since this has important implications.

If an AFP document is requested by an application rather than a browser, then it is the responsibility of that application to interpret the returned response and to request the new page.

A request issued by a browser is in fact a new request. If multiple AFP instances are running there is no assurance that the page triggering Response.Redirect() is actually the page that executes the requested page. It is therefore not possible to use a cursor to save the intermediate results of one page for use by the other page. In addition, an indefinite delay may occur during forwarding, resulting in the processing of requests of other users in the meantime.

Whether it reacts to such messages and how depends on the browser. The Internet Explorer as an example automatically loads the stated URL. The current page will not be displayed in the browser. It is therefore not possible to display a "Please wait..." message on the screen and then automatically refer to the page that displays the result. For this refresh a META tag is required:

<meta http-equiv="refresh" content="1;url=<%?Session.Url("newpage.afp")%>">

With this line you instruct the browser to render the current page and to automatically load the page newpage.afp after one second. Forwarding through the META tag in the Internet Explorer can, however, be deactivated, whereas this is not possible with HTTP message 302. It is therefore recommended to additionally return a text with a link:

If you are not automatically forwarded, please click <a href="<%?Session.Url("newpage.afp")%>">here</a>...

The advantage of Response.Redirect() over Server.Execute(), Server.Transfer() or Response.Call() lies in the fact that the browser is aware of the new page. If the user reloads the page, e.g. with F5 in the Internet Explorer, then the browser will only request the new page.

If, however, forwarding was effected by a different method, then only the server knew about it. The browser will therefore request the page that was originally called. If that page is not set up for this and makes a new forward, then it appears as if the wrong page would be displayed.

See also

Response.Call() | Server.Transfer() | Server.Execute()