Name

HttpResponse

Synopsis

The HttpResponse class is used to send information to the client’s browser, including HTML content, HTML headers, and customized cookies. Its name derives from the fact that it is used to “respond” to an HTTP request.

The Redirect() method of the HttpResponse class provides the easiest way to programmatically send the user to another web page. You supply the name of the HTML or ASPX file as an argument (e.g., Response.Redirect ("newpage.aspx")). As long as the file is in the same directory as the current page, you don’t need to provide a full URL (like http://www.mysite/myapplication/newpage.aspx), although you can use a relative path or fully-qualified URL. Other ways to transfer a user between pages in an ASP.NET program include the HttpServerUtility.Transfer() method and the System.Web.UI.WebControls.HyperLink web control.

The Cookies property of the HttpResponse class provides a reference to the application’s HttpCookieCollection, which can send custom cookies to the client. The Cache property provides a reference to the application’s HttpCachePolicy settings. Both classes are described separately. These properties, along with the Redirect() method, are the most commonly used members of HttpResponse.

In traditional ASP development, the Write() method was often used to append HTML to a web page (e.g., Reponse.Write "<h1>Hello World</h1>"). ASP.NET programs will rarely use this method because it is much easier to handle dynamic content by changing ...

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.