Response.Redirect in Classic ASP

Response.Redirect tells the visitor’s browser to request a different URL. In Classic ASP, call it before HTTP headers have been sent; do not place it after a Response.Flush that has committed those headers.

<%
Response.Redirect "https://www.plus2net.com/asp-tutorial/response.php"
%>

The browser makes a new request for the destination. The original example used https://www.sitename.com; substitute the actual, trusted destination for your application.

On this page — Show page sectionsHide page sections

Syntax and redirect targets

Response.Redirect "destination-url"

Use a full URL to redirect to another site or a root-relative URL to stay on the same site:

<%
Response.Redirect "/asp-tutorial/response-write.php"
%>

Why the redirect must happen early

When headers have already been committed, attempting a redirect can raise a Classic ASP header error. The original lesson showed a representative ASP 0156 error:

Response object error 'ASP 0156 : 80004005'
Header Error
The HTTP headers are already written to the client browser.

Make the routing or login decision at the start of the page, before HTML output, flushing, or other operations that commit the response.

Full Classic ASP redirect page

<%@ Language="VBScript" %>
<% Option Explicit
Response.Buffer = True
Response.Redirect "/asp-tutorial/response.php"
%>

Save as an .asp page on IIS. It redirects without rendering a normal HTML page; the buffer setting must be made before any content is sent.

Redirect after a simple condition

<%@ Language="VBScript" %>
<% Option Explicit
Response.Buffer = True
Dim signedIn
signedIn = (Session("userid") <> "")
If Not signedIn Then
  Response.Redirect "/asp-tutorial/lg-login.php"
End If
Response.Write "Login session is present."
%>
Security: This only demonstrates branching on a session value. A production member page needs a full authentication and authorization check; a nonempty session variable alone is not sufficient.

Avoid open redirects from query parameters

Do not pass an untrusted query-string value directly into Response.Redirect. Restrict the destination to a list of trusted, intended routes:

<%
Dim pageKey, destination
pageKey = LCase(Trim(Request.QueryString("page")))
Select Case pageKey
  Case "write"
    destination = "/asp-tutorial/response-write.php"
  Case "flush"
    destination = "/asp-tutorial/response-flush.php"
  Case Else
    destination = "/asp-tutorial/response.php"
End Select
Response.Redirect destination
%>

The query parameter can choose only one of the allowed paths. This prevents an attacker from making your site redirect visitors to arbitrary external URLs.

Redirect after a POST

A common workflow saves form data and then redirects to a result page to avoid repeating a form submission on refresh. For a real form, validate the input, perform the write safely, and only then redirect:

<%
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
  ' Validate and save the form data here.
  Response.Redirect "/asp-tutorial/response.php"
End If
%>

This is an outline, not a complete database handler. A conventional Classic ASP Response.Redirect issues a temporary redirect; if a specific HTTP status is required, configure it deliberately at the appropriate server layer.

Response.Redirect versus other methods

MethodBehavior
Response.RedirectBrowser navigates to another URL
Response.EndEnds this response; no new destination
Response.FlushCommits/sends currently buffered output
Response.ClearDrops unsent body output

Common errors and troubleshooting

If ASP reports a header error, ensure the redirect occurs before output is sent. If the browser stays on the same page, check for a wrong URL or redirect loop. If user input controls the destination, allowlist possible targets. For server-level permanent redirects, see the ASP redirect guide and your IIS configuration.

For a comparison in another language, see header redirects in PHP. Classic ASP uses Response.Redirect rather than PHP's header().

Frequently asked questions

Does Response.Redirect make a 301 permanent redirect?

Classic ASP Response.Redirect ordinarily performs a temporary redirect. For permanent relocation, configure an appropriate 301 at IIS/server level rather than assuming the method is permanent.

Can I redirect to a page on the same site?

Yes. Use a suitable root-relative path or an absolute URL.

Should I add Response.End after Response.Redirect?

No. Classic ASP Response.Redirect already terminates processing; adding Response.End is unnecessary.

Can I redirect after Response.Flush?

Not after response headers are committed. Put redirect decisions before any flush.

Back to top ↑


ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer