Skip to Main Content
C# in a Nutshell, Second Edition
book

C# in a Nutshell, Second Edition

by Peter Drayton, Ben Albahari, Ted Neward
August 2003
Intermediate to advanced content levelIntermediate to advanced
928 pages
32h 1m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell, Second Edition

Name

Uri

Synopsis

This class encapsulates a complete URI (Uniform Resource Identifier) and provides various parts of it through properties. For example, you can get the Scheme (e.g., http, https, mailto) and the Port number. For http, the default port is 80, if not specified in the Uri (ftp uses port 21, https uses 443, and mailto uses 25). You can also retrieve the query-string arguments—including the initial question mark—from the Query property, or the fragment portion—including the fragment marker (#)—from the Fragment property. Some Boolean properties include IsLoopback, which indicates true if the Uri references the local host, and IsUnc, which indicates true if the Uri is a UNC path (such as \\server\folder).

The Uri constructors perform some basic cleanup of your parameters before creating a Uri, including converting the scheme and hostname to lowercase, removing default and blank port numbers, and removing the trailing slash (/). Instances of Uri have read-only properties. To modify a Uri, use a UriBuilder object.

The Uri class also provides static helper methods such as EscapeString( ), which converts a string to a valid URL by converting all characters with an ASCII value greater than 127 to hexadecimal representation. The CheckHostName( ) and CheckSchemeName( ) methods accept a string and check if it is syntactically valid for the given property (although they do not attempt to determine if a host or URI exists).

The Uri class is used by many .NET types, including some ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# in a Nutshell

C# in a Nutshell

Ben Albahari, Ted Neward, Peter Drayton
C# 7.0 in a Nutshell

C# 7.0 in a Nutshell

Joseph Albahari, Ben Albahari
C# Cookbook, 2nd Edition

C# Cookbook, 2nd Edition

Jay Hilyard, Stephen Teilhet
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard

Publisher Resources

ISBN: 0596005261Catalog PageErrata