Library code snippets

Redirecting Without Halting Execution

This snippet demonstrates how to send a redirect to a client without halting execution. This can be useful if you want the client to be immediately request a fresh page leaving your ASP script to continue processing a time consuming task.

Response.Buffer = True
' Set the HTTP Status to 302 (Moved)
Response.Status = "302 Moved Temporarily"
' Add a Location HTTP Header
Response.addheader "Location", "http://www.the-redirect-url.com"
' Add a Content-Length header equal to zero so that client assumes
' there is nothing coming after the http headers
Response.addheader "Content-Length", "0"
' Flush the buffered response
Response.Flush

' Do time consuming stuff here...

 

Comments

  1. 08 Jun 2007 at 00:33
    Very useful, glad I saw it
  2. 01 Jan 1999 at 00:00

    This thread is for discussions of Redirecting Without Halting Execution.

Leave a comment

Sign in or Join us (it's free).

Lee Gunn - .NET C# Scotland Lee Gunn is a freelance Microsoft Certified Developer based in Glasgow, Scotland. Specialising in quality driven Internet solutions, largely built around Microsoft’s .NET platform. Skills used o...

Want to stay in touch with what's going on? Follow us on twitter!