Response.End in Classic ASP

Response.End stops processing the current Classic ASP page immediately. Output written before it is returned; statements after it are not executed. Use it for an intentional early exit when the remainder of the page must not run.

<%
Response.Write "Message No 1: Before End<br>"
Response.Write "Message No 2: Also before End<br>"
Response.End
Response.Write "Message No 3: Never executed<br>"
%>

Only messages 1 and 2 appear. The third statement is unreachable because Response.End stops processing this ASP request.

On this page — Show page sectionsHide page sections

Syntax

Response.End

Complete standalone original example

<%@ Language="VBScript" %>
<% Option Explicit
Response.Buffer = True
%>
<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"><title>Response.End</title></head>
<body>
<%
Response.Write "Message No :1 Before Flush <br>"
Response.Write "Message No :2 After Flush <br>"
Response.End
Response.Write "Message No :3 After End, not executed <br>"
%>
</body>
</html>

The original example described the first and second messages as “before/after Flush,” although no Response.Flush call was present. The important behavior is that both messages precede Response.End; the later output is skipped.

Exit an invalid request early

<%
Dim pageNo
pageNo = Trim(Request.QueryString("page"))
If Not IsNumeric(pageNo) Then
  Response.Write "Provide a numeric page value."
  Response.End
End If
Response.Write "Page parameter accepted."
%>

This demonstrates an early exit, not full numeric validation: IsNumeric accepts some formats you might not want for a page number. Validate integer range and format separately for a real application.

Stop after returning plain text

<%
Response.Buffer = True
Response.ContentType = "text/plain"
Response.Write "Task completed"
Response.End
%>

A plain-text response does not need additional HTML below the End statement.

Response.End versus Exit Sub and Exit Function

<%
Sub ShowGreeting()
  Response.Write "Hello from a procedure"
  Exit Sub
  Response.Write "Not executed in this procedure"
End Sub
ShowGreeting()
Response.Write "Page continues"
%>

Exit Sub leaves only the procedure. Response.End stops the whole ASP page. Use the narrower control-flow statement when the rest of the response should still run.

End versus Clear and Redirect

MethodPurpose
Response.EndTerminate current ASP script
Response.ClearDiscard only buffered response body
Response.RedirectTell the client to request a new URL; in Classic ASP it ends the current page response

Avoid accidentally skipping cleanup

Statements below Response.End will not run. Close open database resources and complete necessary state changes before ending the response, or organize the code so early termination does not skip required work. Keep authentication and authorization checks at the start of protected pages.

Common errors

If expected output is missing, check for earlier Response.End calls. If a redirect seems to require an extra Response.End, it generally does not—Classic ASP Response.Redirect itself ends the response. Do not confuse these methods with similarly named ASP.NET APIs.

Frequently asked questions

Will Response.End send the content already in the buffer?

It stops processing and returns the current ASP response; content already written before the call is part of that result.

Can I execute code after Response.End?

No. Put required operations before it or use a narrower exit statement.

Do I need Response.End after Response.Redirect?

No, not in Classic ASP. Redirect itself terminates processing.

Does Response.End log a user out?

No. It stops processing. To end a session, use the Session methods such as Session.Abandon where appropriate.

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