Chapter 45: ASP Response Object
1. What is the Response Object?
The Response object is the server’s mouthpiece — everything you want to send to the browser (HTML, headers, cookies, redirects, status codes, content type, etc.) goes through the Response object.
In simple words:
- Request = what the browser sends to the server
- Response = what the server sends back to the browser
Without Response, your ASP page would do calculations silently and send nothing to the user.
2. The Most Important Response Methods & Properties
Here are the ones you will use every single day in Classic ASP — ranked by how often you actually wrote them in real code.
| Method / Property | What it does | Real-world frequency | Example |
|---|---|---|---|
| Response.Write | Sends text/HTML to the browser | ★★★★★ (most used) | Response.Write “<p>Hello</p>” |
| <%= expression %> | Shortcut for Response.Write expression | ★★★★★ | <%= Now() %> |
| Response.Redirect | Sends 302 redirect to browser | ★★★★☆ | Response.Redirect “login.asp” |
| Response.Cookies(“key”) = value | Sets a cookie | ★★★★☆ | Response.Cookies(“User”) = “Rahul” |
| Response.End | Stops processing and sends what has been written | ★★★☆☆ | After error or redirect |
| Response.Flush | Sends buffered content immediately | ★★☆☆☆ | Long pages / progress feedback |
| Response.Buffer = True/False | Turns buffering on/off (default True) | ★★☆☆☆ | Response.Buffer = False for streaming |
| Response.ContentType | Sets MIME type (text/html, application/json, etc.) | ★★☆☆☆ | Response.ContentType = “application/json” |
| Response.Status | Sets HTTP status code | ★☆☆☆☆ | Response.Status = “404 Not Found” |
| Response.AddHeader | Adds custom HTTP header | ★☆☆☆☆ | Response.AddHeader “X-Custom”, “value” |
3. Basic Example 1 – Hello World with Response.Write
|
0 1 2 3 4 5 6 |
<%@ Language=VBScript %> <% Option Explicit %> <!DOCTYPE html> <html> <body> <h1>ASP Response Object Example</h1> <% ' Long way (very common in old code) Response.Write "<p>Hello from Hyderabad!</p>" Dim name name = "Rahul" Response.Write "<p>Welcome, " & Server.HTMLEncode(name) & "!</p>" %> <!-- Shortcut way (most people used this) --> <p>Server time right now: <%= Now() %></p> </body> </html> |
Important:
- <%= Now() %> = exactly the same as <% Response.Write Now() %>
- Always use Server.HTMLEncode for user-controlled data
4. Example 2 – Form Processing + Response.Redirect
|
0 1 2 3 4 5 6 |
<%@ Language=VBScript %> <% Option Explicit %> <!DOCTYPE html> <html> <body> <h2>Login Page</h2> <form method="post" action="login.asp"> Username: <input type="text" name="username"><br> Password: <input type="password" name="password"><br> <input type="submit" value="Login"> </form> <% If Request.Form("username") <> "" Then Dim u, p u = Trim(Request.Form("username")) p = Trim(Request.Form("password")) If u = "admin" And p = "secret123" Then Session("LoggedIn") = True Session("UserName") = u ' Redirect – very common Response.Redirect "dashboard.asp" Else Response.Write "<p style='color:red;'>Invalid credentials!</p>" End If End If %> </body> </html> |
dashboard.asp (protected page)
|
0 1 2 3 4 5 6 |
<% If Session("LoggedIn") <> True Then ' Redirect if not logged in Response.Redirect "login.asp" End If Response.Write "<h1>Welcome, " & Server.HTMLEncode(Session("UserName")) & "!</h1>" %> |
5. Example 3 – JSON API Endpoint with Response.ContentType
Very common in late Classic ASP sites that added AJAX.
|
0 1 2 3 4 5 6 |
<%@ Language=VBScript %> <% Option Explicit %> <% Response.ContentType = "application/json" Response.Charset = "utf-8" Dim data data = "{""status"":""success"", ""message"":""Hello from Hyderabad"", ""time"":""" & Now() & """}" Response.Write data %> |
→ Browser gets pure JSON → jQuery / JavaScript can parse it easily.
6. Example 4 – Forcing Download (Content-Type + AddHeader)
|
0 1 2 3 4 5 6 |
<% Response.ContentType = "application/pdf" Response.AddHeader "Content-Disposition", "attachment; filename=invoice.pdf" ' Stream the file Dim stream Set stream = Server.CreateObject("ADODB.Stream") stream.Type = 1 ' adTypeBinary stream.Open stream.LoadFromFile Server.MapPath("files/invoice.pdf") Response.BinaryWrite stream.Read stream.Close Set stream = Nothing Response.End %> |
7. Teacher Summary – ASP Response Object in Classic ASP
ASP Response Object is the server’s way to talk back to the browser:
- Response.Write / <%= … %> → send text/HTML
- Response.Redirect → 302 redirect (very common)
- Response.Cookies → set cookies
- Response.ContentType → change MIME type (JSON, PDF, etc.)
- Response.AddHeader → custom headers
- Response.Buffer → control buffering
- Response.Flush → send partial content
- Response.End → stop processing immediately
- Response.Status → set HTTP status code
Always remember:
- Use Server.HTMLEncode for user-controlled output
- Use Response.Redirect after Session changes
- Set .ContentType and .Charset for APIs
- Response.End after redirects/downloads to avoid extra output
This is how millions of Classic ASP pages sent HTML, redirected users, set cookies, returned JSON, and forced downloads — and many legacy Indian systems still use exactly this Response object style in 2026.
Next class?
- Want a full example combining Response + Session + Cookies + login?
- Or how to stream large files without memory issues?
- Or compare Classic ASP Response vs modern ASP.NET Core HttpResponse?
- Or move to the next W3Schools topic (ASP Cookies or ASP Sessions)?
Just tell me — I’m here! 🚀🇮🇳 Keep learning strong, Webliance! 😊
