Exemplo n.º 1
0
        /// <summary>
        /// Updates a relative silverlight uri to an absolute uri
        /// </summary>
        /// <param name="baseUri">the uri passed by the client</param>
        /// <returns>the updated absolute uri</returns>
        private static Uri ConvertToAbsoluteUri(Uri baseUri)
        {
            if (baseUri == null)
            {
                return(null);
            }

#if ASTORIA_LIGHT
            if (!baseUri.IsAbsoluteUri)
            {
#if !WINDOWS_PHONE
                // If we can use XHR, we will and thus we should use the old (V1) way of determining our
                //   base URI. That is, use the uri of the HTML page
                if (XHRHttpWebRequest.IsAvailable())
                {
                    return(new Uri(System.Windows.Browser.HtmlPage.Document.DocumentUri, baseUri));
                }
                else
#endif
                {
                    // Otherwise we are going to use the new Client stack. In this case there might not be any
                    //   HTML page hosting us, or it might not be accessible, so the only base uri we can use
                    //   is the base uri of the xap we're running in.
                    System.Net.WebClient webClient = new System.Net.WebClient();
                    Uri clientBaseAddress          = new Uri(webClient.BaseAddress);
                    return(new Uri(clientBaseAddress, baseUri));
                }
            }
#endif
            return(baseUri);
        }
        /// <summary>
        /// Determines if a request to the specified URI needs to use the Client HTTP stack
        /// or if it should use the XHR HTTP stack.
        /// </summary>
        /// <param name="uri">The uri for the request</param>
        /// <returns>true if the request needs to use the Client HTTP stack, otherwise false</returns>
        private static bool UriRequiresClientHttpWebRequest(Uri uri)
        {
            // If we can use XHR, we will - to maintain backward compat.
            // So if we can use XHR technically (DOM Bridge is allowed and we can actually create the XHR object)
            //   we need to check if running the request through XHR would work, thus we need to figure out if it
            //   will be considered X-Domain. If it's not X-Domain we will use XHR
            // In all other cases (XHR not available because we're Out-Of-Browser, DOM Bridge is not allowed,
            //   running on a non-UI thread, request would be X-Domain and so on) we will use the client stack always.
            if (!XHRHttpWebRequest.IsAvailable())
            {
                return(true);
            }

            // Ideally we would use the algorithm from XHR to determine if the request is X-Domain
            // because we want to use Client for requests which XHR would mark as X-Domain (and thus fail).
            // The best approximation is to compare the request URI to the HTML page URI.
            Uri sameDomainUri = System.Windows.Browser.HtmlPage.Document.DocumentUri;

            // The request is same-domain only if it has same scheme, same domain and same port
            if (sameDomainUri.Scheme != uri.Scheme || sameDomainUri.Port != uri.Port ||
                !string.Equals(sameDomainUri.DnsSafeHost, uri.DnsSafeHost, StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates a relative silverlight uri to an absolute uri
        /// </summary>
        /// <param name="baseUri">the uri passed by the client</param>
        /// <returns>the updated absolute uri</returns>
        private static Uri ConvertToAbsoluteUri(Uri baseUri)
        {
            if (baseUri == null)
            {
                return(null);
            }

#if ASTORIA_LIGHT
            // If we can use XHR, we will and thus we should use the old (V1) way of determining our
            //   base URI. That is, use the uri of the HTML page
            if (!baseUri.IsAbsoluteUri && XHRHttpWebRequest.IsAvailable())
            {
                return(new Uri(System.Windows.Browser.HtmlPage.Document.DocumentUri, baseUri));
            }
#endif
            return(baseUri);
        }