/// <summary> /// Parse Uri for SAS (Shared access signature) information. /// </summary> /// <param name="address">The complete Uri.</param> /// <param name="parsedCredentials">The credentials to use.</param> /// <param name="parsedShareSnapshot">The parsed share snapshot.</param> /// <returns>The file URI without credentials or snapshot info</returns> /// <exception cref="System.ArgumentException">address</exception> /// <remarks> /// Validate that no other query parameters are passed in. /// Any SAS information will be recorded as corresponding credentials instance. /// If credentials is passed in and it does not match the SAS information found, an /// exception will be thrown. /// Otherwise a new client is created based on SAS information or as anonymous credentials. /// </remarks> private static Uri ParseFileQueryAndVerify(Uri address, out StorageCredentials parsedCredentials, out DateTimeOffset?parsedShareSnapshot) { parsedCredentials = null; parsedShareSnapshot = null; if (address == null) { return(null); } if (!address.IsAbsoluteUri) { string errorMessage = string.Format(CultureInfo.CurrentCulture, SR.RelativeAddressNotPermitted, address.ToString()); throw new ArgumentException(errorMessage, "address"); } IDictionary <string, string> queryParameters = HttpWebUtility.ParseQueryString(address.Query); parsedCredentials = SharedAccessSignatureHelper.ParseQuery(queryParameters); return(new Uri(address.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped))); }
public static string GetCanonicalizedResourceString(Uri uri, string accountName, bool isSharedKeyLiteOrTableService = false) { StringBuilder canonicalizedResource = new StringBuilder(ExpectedResourceStringLength); canonicalizedResource.Append('/'); canonicalizedResource.Append(accountName); canonicalizedResource.Append(GetAbsolutePathWithoutSecondarySuffix(uri, accountName)); IDictionary <string, string> queryParameters = HttpWebUtility.ParseQueryString(uri.Query); if (!isSharedKeyLiteOrTableService) { List <string> queryParameterNames = new List <string>(queryParameters.Keys); queryParameterNames.Sort(StringComparer.OrdinalIgnoreCase); foreach (string queryParameterName in queryParameterNames) { canonicalizedResource.Append('\n'); canonicalizedResource.Append(queryParameterName.ToLowerInvariant()); canonicalizedResource.Append(':'); canonicalizedResource.Append(queryParameters[queryParameterName]); } } else { // Add only the comp parameter string compQueryParameterValue; if (queryParameters.TryGetValue("comp", out compQueryParameterValue)) { canonicalizedResource.Append("?comp="); canonicalizedResource.Append(compQueryParameterValue); } } return(canonicalizedResource.ToString()); }