Monday 26 August 2013

What is Request and Response objects in Asp.Net


What is Request and Response objects in Asp.Net

Request  and Response are the properties of the Page class. The Request property allows you to access the HTTPRequest object, which contains information,such as path of the request, about the HTTP request for the page .It is a input stream of client. The Response property allows you to access the HTTPResponse object, which in turn allows you to send data to the browser as the result of the request.It is an output stream of Client 

                     In fact, Request and Response properties map directly to HttpRequest and HttpResponse objects respectively. Therefore,  you can directly access these objects in ASP.NET pages by using the Request and Response properties.

Request =>Read   Response=>Write


Example with Request and Response 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class RequestResponse : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{



}
protected void btnResponse_Click(object sender, EventArgs e)
{

Response.Write("<b><i>Request Type=</i></b>" + Request.RequestType + "</br></br>");

Response.Write("<b><i>BrowserName=</b></i>" + Request.Browser.Type + "</br></br>");

Response.Write("<b><i>IsJavaScript Support=</i></b>" + Request.Browser.JavaScript + "</br></br>");

Response.Write("<b><i>IsCookies Support=</i></b>" + Request.Browser.Cookies + "</br></br>");

Response.Write("<b><i>Request Type=</i></b>" + Request.RequestType + "</br></br>");

Response.Write("<b><i>Language=</i></b>" + Request.UserLanguages[0] + "</br></br>");

Response.Write("<b><i>Ip Address=</i></b>" + Request.UserHostName + "</br></br>");

Response.Write("<b><i>Url=</i></b>" + Request.Url + "</br/></br>");

Response.Write("<b><i>User Agent=</i></b>" + Request.UserAgent + "</br/></br>");

Response.Write("<b><i>User Host Name=</i></b>" + Request.UserHostName + "</br></br>");

Response.Write("<b><i>Physical Path=</i></b>" + Request.PhysicalPath + "</br></br>");

Response.Write("<b><i>Physical Application Path=</i></b>" + Request.PhysicalApplicationPath + "</br></br>");

Response.Write("<b><i>Path=</i></b>" + Request.Path + "</br></br>");

Response.Write("<b><i>Application Path=</i></b>" + Request.ApplicationPath + "</br></br>");

}
}


2 comments: