Asp Response in ASP
Absolutely! Here's a clear explanation of the Response object in Classic ASP:
ASP Response Object
The Response object is used to send output from the server to the client’s browser. It controls what the user sees and also manages HTTP headers.
Commonly Used Response Methods and Properties
| Method / Property | Description | Example |
|---|---|---|
Response.Write | Sends text (HTML or plain text) to the client | <% Response.Write "Hello World" %> |
Response.Redirect | Redirects user to another URL | <% Response.Redirect("login.asp") %> |
Response.ContentType | Sets the MIME type of the output | <% Response.ContentType = "application/json" %> |
Response.AddHeader | Adds HTTP headers | <% Response.AddHeader "Refresh", "5; url=home.asp" %> |
Response.Buffer | Enables/disables response buffering | <% Response.Buffer = True %> |
Response.Flush | Sends buffered content immediately | <% Response.Flush %> |
Response.Cookies | Used to send cookies to the client | <% Response.Cookies("UserName") = "Alice" %> |
Response.End | Stops page processing and sends output immediately | <% Response.End %> |
Examples
1. Writing Output
<%Response.Write "<h1>Welcome to my site</h1>"Response.Write "Current Time: " & Now()%>2. Redirecting to Another Page
<%If Session("LoggedIn") <> True Then Response.Redirect "login.asp"End If%>3. Setting Content Type
<%Response.ContentType = "application/pdf"' Then write PDF binary data here...%>4. Setting a Cookie
<%Response.Cookies("UserName") = "Alice"Response.Cookies("UserName").Expires = DateAdd("d", 30, Now()) ' Expires in 30 days%>Notes
Response.Writeis the most common method to send HTML or text to the browser.Use
Response.Redirectto send users to a different page (issues a 302 HTTP redirect).Enable buffering (
Response.Buffer = True) to send the complete output at once.Always be careful with
Response.End— it stops the script immediately.Cookies set via
Response.Cookiesare sent in the HTTP headers and available on the next request.
If you want examples on:
Using
Responsewith headers,Outputting files for download,
Sending JSON or XML,
Or anything else about ASP Response,
just let me know!