Andrew Aitken

Blog

Getting parts of a Uri

Thu 21 May 2015 .net c#

One thing that keeps coming up, but not enough for me to actually remember what I learnt last time, is how to get different parts of a request Uri

So I made a little console app that outputs the different parts from two example Uris.

Behold

Uri Properties:

Using          : https://www.example.com/folder/page.aspx?query=1&sample=2#anchor
AbsolutePath   : /folder/page.aspx
AbsoluteUri    : https://www.example.com/folder/page.aspx?query=1&sample=2#anchor
Authority      : www.example.com
DnsSafeHost    : www.example.com
Fragment       : #anchor
Host           : www.example.com
HostNameType   : Dns
IsAbsoluteUri  : True
IsDefaultPort  : True
IsFile         : False
IsLoopback     : False
IsUnc          : False
LocalPath      : /folder/page.aspx
OriginalString : https://www.example.com/folder/page.aspx?query=1&sample=2#anchor
PathAndQuery   : /folder/page.aspx?query=1&sample=2
Port           : 443
Query          : ?query=1&sample=2
Scheme         : https
Segments       : /, folder/, page.aspx
UserEscaped    : False
UserInfo       :

Using          : http://www.example.com/folder
AbsolutePath   : /folder
AbsoluteUri    : http://www.example.com/folder
Authority      : www.example.com
DnsSafeHost    : www.example.com
Fragment       : 
Host           : www.example.com
HostNameType   : Dns
IsAbsoluteUri  : True
IsDefaultPort  : True
IsFile         : False
IsLoopback     : False
IsUnc          : False
LocalPath      : /folder
OriginalString : http://www.example.com/folder
PathAndQuery   : /folder
Port           : 80
Query          : 
Scheme         : http
Segments       : /, folder
UserEscaped    : False
UserInfo       :

Uri.GetLeftPart(UriPartial part)

Using                : https://www.example.com/folder/page.aspx?query=1&sample=2#anchor
UriPartial.Authority : https://www.example.com
UriPartial.Path      : https://www.example.com/folder/page.aspx
UriPartial.Query     : https://www.example.com/folder/page.aspx?query=1&sample=2
UriPartial.Scheme    : https://

Using                : http://www.example.com/folder
UriPartial.Authority : http://www.example.com
UriPartial.Path      : http://www.example.com/folder
UriPartial.Query     : http://www.example.com/folder
UriPartial.Scheme    : http://

Older Articles

Comma seperated lists

Fri 18 January 2013 .net c#

While working on a site recently I had to output the name property from a list of objects that had been selected by the user.

I wrote a handy little method that let me pass in the objects and a Func to select the property to be used in the ...

Read more

The CacheDependency will monitor a file or folder for changes. When it detects a change it will remove the associated key from the cache.

This comes in quite handy for my hangman game which stores the film titles in an xml file.

Below is how I cache the data and ...

Read more

Page 1 / 1