ASP.NET Request object cheat sheet

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

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

Computers & Internet Web Development Website Hosting

500 Internal Server Error after migrating from IIS 7.5 to IIS 10

by John Avis | November 4, 2019

As support ends for Microsoft Windows Server 2008 I have recently gone through migrating some websites to a new server running Windows Server 2016 and IIS 10 but some of the websites did not work.


Jquery/Javascript Web Development

tagInput: A simple jQuery plugin for tag entry using Bootstrap 4

by John Avis | October 15, 2019

For a website project I needed a way to enter multiple tags. I just wanted something simple that I could easily modify to suit my own needs, so I wrote my own.


ASP.NET Web Forms Web Development

ASP.NET bug with RadioButton GroupName in Repeater

by John Avis | September 1, 2019

I rediscovered a bug in ASP.NET that affects RadioButtons inside repeaters. Here is my solution to the problem.

Comments

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

Leave a Comment

Tags

About me

...random postings about web development and programming, Internet, computers, electronics and automotive topics.

Subscribe

Get the latest posts delivered to your inbox.