O'Reilly logo

ASP.NET in a Nutshell by Matthew MacDonald, G. Andrew Duthie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required