private static string GetCanonicalKey(string key)
{
if( key == null ) {
throw new ArgumentNullException("key");
}
try {
Uri uri = new Uri(key);
key = uri.GetParts(UriComponents.Scheme | UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.SafeUnescaped);
new WebPermission(NetworkAccess.Connect, new Uri(key)).Demand();
}
catch(UriFormatException e) {
throw new ArgumentException(SR.GetString(SR.net_mustbeuri, "key"), "key", e);
}
return key;
}
}