Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 4483 |  Welcome, Guest!   Register  Login
Home > Articles > ASP.NET > Useful properties of Request object in ASP.NET

Useful properties of Request object in ASP.NET

1 vote(s)
Rating: 5 out of 5
Article posted by SheoNarayan on 6/2/2008 | Views: 22922 | Category: ASP.NET | Level: Intermediate red flag


In our day to day life of ASP.NET Application development we deal with System.Web.HttpRequest (Request) object. I feel there are many properties available with Request object that does wonderful job but we hardly know or use them. In this article I am trying to explain few of them that I found very useful.

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 <b> 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 <div> 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 <font> 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 <form> html element.

Request.Browser.SupportsSelectMultiple: True - Gets a value indicating whether browser supports multiple selection in the <select> html element.

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 <table> 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 !!!

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

About Sheo Narayan

Experience:8 year(s)
Home page:http://www.snarayan.com
Member since:Tuesday, July 08, 2008
Level:HonoraryPlatinum
Status: [Microsoft_MVP] [Administrator]
Biography:Microsoft MVP, Author, Writer, Mentor & architecting applications since year 2001.

Connect me on Facebook | Twitter | LinkedIn | Blog

>> Write Response - Respond to this post and get points
Related Posts

This article describes an approach to take backup and restore any database that is supported by .NET. In this article, I have taken SQL Server as an example however similar approach can be followed to backup and restore MySql, Oracle and any other databases.

In this article we are going to learn how to read and write multi-valued cookies in ASP.NET. Multi-valued cookies is just like a normal cookies however it gives us flexibility to store multiple data in a single cookies using subkeys.

Writing here to describe what is event validation in Asp.Net. Once during development I got below error when I was trying do post back using selected index Change event of a DropDown and I know you might have somewhere got this during development.

In this article we shall learn how to fire Server Side method on click of the button, how to access the CommandName property of the asp: Button (using OnCommand event) and what is the use of it and how to access the CommandName property of the asp:Button (using OnClick event) and what is the use of it.

There are situations where we would like to detect if the post back is from a form interaction (i.e. submit or button clicks) or is it by hitting the browser F5 refresh button. Many of them will jump saying how about checking ‘Ispostback’ value. ‘IsPostback’ will always have the value which was set previously. So for instance if the page was posted back before refresh, then the value will be true and if the page is not posted back before refresh, then the value will be false.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2012 7:47:11 AM