Pages

Tuesday, November 23, 2010

Useful properties of Request object in ASP.NET

System.Web.HttpRequest (Request) object is used to get the information about the user. In this article, I am trying to show some useful properties of Request object that is very handy and useful while developing ASP.NET applications.

I have presented this information by taking example of a url http://localhost/myfunda/test.aspx?q=search&re=afdsf where "localhost" is my local IIS, "myfunda" is a virtual directory name and "test.aspx" page is the name of the page where the request object property has been written.

Follwing example has been show in the format of

Request Object: Result - Description
Request object

Request.Path: /myfunda/test.aspx - Is used to get information about the path of the url from where the request is being made.

Request.Cookies: - Get the collection of cookies, To know more about cookie, refer to http://www.dotnetfunda.com/articles/article61.aspx

Request.ContentLength: 0 - Returns the length of content sent by the browser.

Request.IsLocal: True - Returns the value indicating whether the request is from local computer.

Request.IsSecureConnection: False - Returns the value indicating whether the connection is secure (using HTTPS).

Request.PhysicalApplicationPath: C:\Web\MyFunda.Web\ - Returns physical application path.

Request.PhysicalPath: C:\Web\MyFunda.Web\test.aspx - Returns physical path of the file being requested.

Request.QueryString: q=search&re=afdsf - Returns all querystrings excluding ?.

Request.RawUrl: /myfunda/test.aspx?q=search&re=afdsf - Returns the url (including the virtual directory if any) of the page along with querystring.

Request.UserHostAddress: 60.243.141.170 - Returns the ip address of remote client.

Request.UserHostName: 60.243.141.170 - Returns the host name (DNS Name) if specified or returns the ip address of the remote client.

Request.ApplicationPath: /myfunda - Returns the virtual application root path.

Request.Url: http://localhost/myfunda/test.aspx?q=search&re=afdsf - Returns the complete url of the current request as appears in web browser address bar.
Request.Url object

Request.Url.AbsolutePath: /myfunda/test.aspx - Returns the absolute path (no querystrings)

Request.Url.AbsoluteUri: http://localhost/myfunda/test.aspx?q=search&re=afdsf - Returns the absolute URI, almost same as Request.Url.

Request.Url.Authority: localhost - Returns the IP Host name or IP Address of the server.

Request.Url.Host: localhost - Returns the host of this instance.

Request.Url.HostNameType: Dns - Gets the type of the host specified in the uri.

Request.Url.IsDefaultPort: True - Gets whether the port value for the URI is default.

Request.Url.IsFile: False - Gets information whether the specified uri is the file uri.

Request.Url.LocalPath: /myfunda/test.aspx - Gets local file path name

Request.Url.OriginalString: http://localhost:80/myfunda/test.aspx?q=search&re=afdsf - Returns original uri passed to the uri constructor.

Request.Url.PathAndQuery: /myfunda/test.aspx?q=search&re=afdsf - Returns the path and querystring of the uri.

Request.Url.Port: 80 - Gets the port number of the uri.

Request.Url.Query: ?q=search&re=afdsf - Gets the querystring of the uri along with ?
Request.Browser object

Request.Browser.BackgroundSounds: True - To know whether browser supports background sound.

Request.Browser.Beta: False - To know whether current version is in Beta release.

Request.Browser.Browser: AppleMAC-Safari - Get the browser string (if any).

Request.Browser.CanInitiateVoiceCall: False - Get a value indicating whether browser can initiate voice call.

Request.Browser.CanSendMail: True - Get a value indicating whether browser can send email using mailto: .

Request.Browser.Cookies: True - Get a value indicating whether the browser supports cookie.

Request.Browser.Crawler: False - Get a value indicating whether the browser is a search engine web crawler.

Request.Browser.DefaultSubmitButtonLimit: 1 - Get the maximum number of submit button allowed in a form.

Request.Browser.Frames: True - Get a value whether browser supports Frames.

Request.Browser.HasBackButton: True - Get a value whether browser has a dedicated back button.

Request.Browser.Id: safari1plus - Get the internal identifier of the browser as specified in tbe browser definition file.

Request.Browser.InputType: keyboard - Returns the type of input supported by the browser.

Request.Browser.IsColor: True - Get a value indicating whether the browser has a color display.

Request.Browser.IsMobileDevice: False - Get a value indicating whether the browser is a mobile device (if recognized).

Request.Browser.JavaApplets: True - Get a value indicating whether the browser supports Java applets.

Request.Browser.JavaScript: True - Get a value indicating whether the browser supports JavaScript.

Request.Browser.EcmaScriptVersion: 1.4 - Get the version number of Ecma script supported by browser.

Request.Browser.JScriptVersion: 0.0 - Get the version of the JScript supported by the browser.

Request.Browser.MajorVersion: 5 - Get the major version of the browser.

Request.Browser.MinorVersion: 0 - Get the minor version of the browser.

Request.Browser.MaximumHrefLength: 10000 - Get maximum number of characters supported for href (hrml link) element

Request.Browser.MaximumRenderedPageSize: 20000 - Get maximum length of the page in byte browser can display.

Request.Browser.MaximumSoftkeyLabelLength: 5 - Get maximum length of the text that a soft key label can display.

Request.Browser.MobileDeviceManufacturer: Unknown - Get the name of the mobile device manufacturer, if identifiable.

Request.Browser.MobileDeviceModel: Unknown - Get the name of the model number of mobile device , if identifiable.

Request.Browser.Platform: WinXP - Get the name of the platform client is using.

Request.Browser.PreferredRenderingType: html32 - Get the name of the type of content browser prefer to get.

Request.Browser.ScreenBitDepth: 24 - Get the depth of the display, a bits per pixel.

Request.Browser.ScreenCharactersHeight: 40 - Returns the approximate height of the display in lines.

Request.Browser.ScreenCharactersWidth: 80 - Returns the approximate width of the display in characters.

Request.Browser.ScreenPixelsHeight: 480 - Returns the approximate height of the screen in pixel.

Request.Browser.ScreenPixelsWidth: 640 - Returns the approximate width of the screen in pixel.

Request.Browser.SupportsBold: True - Gets a value indicating whether browser supports html element.

Request.Browser.SupportsCacheControlMetaTag: True - Gets a value indicating whether browser supports cache control value in the META element.

Request.Browser.SupportsCss: True - Gets a value indicating whether browser supports CSS.

Request.Browser.SupportsDivAlign: True - Gets a value indicating whether browser supports align attribute of the
html element.

Request.Browser.SupportsEmptyStringInCookieValue: True - Gets a value indicating whether browser supports null in cookie values.

Request.Browser.SupportsFontColor: True - Gets a value indicating whether browser supports color attribute in html element. In the same way, we have for font size, font name etc.

Request.Browser.SupportsImageSubmit: True - Gets a value indicating whether browser supports submission of form using a custom image in place of a button.

Request.Browser.SupportsQueryStringInFormAction: True - Gets a value indicating whether browser supports querystring in the action attribute of the
html element.

Request.Browser.SupportsSelectMultiple: True - Gets a value indicating whether browser supports multiple selection in the DropDown

Request.Browser.SupportsXmlHttp: False - Gets a value indicating whether browser supports receiving xml over HTTP.

Request.Browser.Tables: True - Gets a value indicating whether browser supports receiving html element.

Request.Browser.Type: Desktop - Can be used to Get name and major version of the browser.

Request.Browser.VBScript: False - Gets the value whether browser supports VBScript .

Request.Browser.Version: 5.0 - Gets the full version of the browser.

Request.Browser.Win32: True - Gets the value indicating whether the client is using Win32 based system.

There of course many more properties than I have conver in this article, however I felt these are most frequently used and useful to know. Thanks for reading and please add other useful information related to Request if you have by responding to this article.

Happy Coding !!!

1 comment:

Anonymous said...

nice, love this blog, how do I subscribe