ASP.NET Request object cheat sheet

John Avis by | August 8, 2014 | ASP.NET Web Forms

Personally I can never remember which of the Request object properties I need to use to get the requested URL or certain parts of the requested URL.
Personally I can never remember which of the Request object properties I need to use to get the requested URL or certain parts of the requested URL.

This cheat sheet lists the commonly used properties for this purpose, a description, and some examples of what possible values to expect.

Request.ApplicationPath
Returns the path relative to the website root.
/

Request.CurrentExecutionFilePath
Returns the path relative to the website root.
/test.aspx

Request.CurrentExecutionFilePathExtension
Returns the file extension of the requested page.
.aspx

Request.FilePath
Returns the path without querystring.
/test.aspx

Request.Path
Returns the full path without querystring.
/test.aspx?key=value

Request.RawUrl
Returns the full path and querystring.
/test.aspx?key=value

Request.PhysicalApplicationPath
Returns the file location of the website directory.
c:\wwwroot\

Request.PhysicalPath
Returns the page file name including file location.
c:\wwwroot\test.aspx

Request.QueryString
Returns the querystring without the leading question mark. If no querystring then returns an empty string.
key=value

Request.RequestType
Returns the request method as a string.
GET
POST


Request.Url
Returns the full URL including protocol, domain name, port (only if not 80), full path and querystring.
http://domain.com/test.aspx?key=value
http://domain.com:61615/Test.aspx?key=value

Request.Url.AbsolutePath
Returns the full path.
/test.aspx

Request.Url.AbsoluteUri
Returns the the full URL including protocol, domain name, port (only if not 80), full path and querystring.
http://domain.com/test.aspx?key=value
http://domain.com:61615/Test.aspx?key=value


Request.Url.Host
Returns only the host name (domain name including any requested sub-domain)
www.domain.com
my.test.domain.com

Request.Url.OriginalString
Returns the full URL including protocol, domain name, port, full path and querystring.
http://domain.com:80/test.aspx?key=value

Request.Url.PathAndQuery
Returns the full path and querystring.
/test.aspx?key=value

Request.Url.Query
Returns the querystring portion only, including the leading question mark. If there is no querystring then it returns an empty string.
?key=value

Request.Url.Scheme
Returns the protocol as a string.
http
https


Request.Url.Segements
Returns a string array of the path split by forward slashes.
{ /, folder/, test.aspx }

Important note regarding default pages

If the default page is requested without using the page name (ie. just the domain name or folder name) all of these methods except Request.RawUrl will still return the default page's name. If you need to know exactly what was requested use Request.RawUrl.

Important notes regarding querystrings

If the querystring is blank but a question mark was provided, all of these methods except Request.RawUrl will not include the question mark. If you need to know exactly what was requested use Request.RawUrl.

If a querystring key is requested but without equals sign and value, then all methods return the querystring exactly as entered, eg. ?key1=value&key2&key3=value.

Important note regarding upper and lower case in requests

Host names are always returned in lower case, regardless of how entered.

All methods return the case exactly as entered for the path and querystring, regardless of the actual case used for the physical folder or file name.

Related Posts

ASP.NET Web Forms Bootstrap

More on Bootstrap 4 modals in ASP.NET Web Forms applications using UpdatePanels

by John Avis | April 9, 2019

In this, my third post on this topic, I go over the methods I am using now and the problems I have encountered and overcome.


ASP.NET Web Forms Classic ASP

Custom error pages for ASP.NET Web Forms and Classic ASP in IIS 7 and 8.5

by John Avis | February 20, 2019

I was recently doing some work on a website which has a mixture of older Classic ASP pages and ASP.NET Web Forms pages and ran into problems with custom error pages.


ASP.NET Web Forms

Nicer localised UpdateProgress’ for your ASP.NET pages with multiple UpdatePanels

by John Avis | February 9, 2018

On an ASP.NET Web Forms page with multiple UpdatePanels it’s nice to give the user some feedback when one of the panels is being updated.

Comments

There are no comments yet. Be the first to leave a comment!

Leave a Comment
Tags
ASP.NET Html Forms ASP.NET MVC ASP.NET Web Forms ASP.NET Web Pages Bootstrap C# Classic ASP Cool Websites Databases eBay and PayPal Electrical Repairs General Hardware HTML/CSS Jquery/Javascript Media Center Mobile Phones Responsive Web Design Reviews SEO and Social Networking Web Design Web Development Web Security web+db Website Hosting Windows XP Youtube

About me

...mostly about web development and programming, with a little bit of anything else related to the Internet, computers and technology.

Subscribe

Get the latest posts delivered to your inbox.