ASP Response Object
Explore the ASP Response object, the built-in object your script uses to send output, redirect visitors, and store cookies in the browser.
What Is the Response Object?
The Response object represents the HTTP response your ASP page sends back to the browser. It is built into every ASP page automatically — you never create it yourself. Whenever you want to send text to the visitor, send them somewhere else, or remember something about them between requests, you do it through Response.
Writing Output with Response.Write
Example: Response.Write and its shorthand
<%
Dim visitorName
visitorName = "Priya"
Response.Write("Hello, " & visitorName & "!")
%>
<p>Or write the shorthand way: <%= visitorName %></p>Note: The angle-bracket-equals tag is shorthand for Response.Write. Writing that expression between <%= and %> sends the same output as calling Response.Write(expression) — use whichever reads more naturally in context, mixed in with your HTML.
Redirecting with Response.Redirect
Example: Redirecting an unauthenticated visitor
<%
Dim isLoggedIn
isLoggedIn = False
If Not isLoggedIn Then
Response.Redirect "login.asp"
End If
Response.Write("Welcome back to the dashboard!")
%>Note: Response.Redirect works by sending an HTTP header telling the browser to go elsewhere, and headers must be sent before any actual page content. If your script has already used Response.Write or output any HTML before calling Response.Redirect, you will get a "headers already written" error. Setting Response.Buffer = True at the top of the page, or simply placing redirect checks before any output, avoids the problem.
Setting Cookies with Response.Cookies
Example: Saving a cookie for 30 days
<%
Response.Cookies("username") = "priya92"
Response.Cookies("username").Expires = DateAdd("d", 30, Now())
Response.Write("Cookie saved. We'll remember you for 30 days.")
%>Note: A cookie set with Response.Cookies is only sent to the browser along with that response — it does not appear back on your own script's variables right away. On the visitor's next request, the browser sends the cookie back automatically, and you read it using Request.Cookies, covered in the next lesson.