ASP.NET Request object cheat sheet

By · August 8, 2014 · 0 comments

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.RawUrl
Returns the full path and querystring.
/test.aspx?key=value

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.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 no querystring then returns an empty string.
?key=value

Request.Url.Scheme
Returns the protocol.
http
https
Read more...
ASP.NET Web Forms

Get the latest posts delivered to your inbox.

Comments

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

Leave a Comment

All comments are moderated and rel="nofollow" is in use. Avatars are sourced from gravatar.com – a globally recognised avatar.

Type the numbers from the picture above

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

profile for John at Stack Overflow, Q&A for professional and enthusiast programmers
Subscribe

Get the latest posts delivered to your inbox. *