/// <devdoc>
        /// Gets an XmlReader representing XML or XSL content, and optionally a cache
        /// dependency for that content.
        /// Supported paths are: Relative paths, physical paths, UNC paths, and HTTP URLs
        /// If a path is not provided, the content parameter is assumed to contain the
        /// actual content.
        /// If there is no data, null is returned.
        /// This method is fully compatible with Virtual Path Providers.
        /// </devdoc>
        private XmlReader GetReader(string path, string content, out CacheDependency cacheDependency)
        {
            // If a filename is specified, load from file. Otherwise load from inner content.
            if (path.Length != 0)
            {
                // First try to detect if it is an HTTP URL
                Uri  uri;
                bool success = Uri.TryCreate(path, UriKind.Absolute, out uri);
                if (success)
                {
                    if (uri.Scheme == Uri.UriSchemeHttp)
                    {
                        // Check for Web permissions for the URL we want
                        if (!HttpRuntime.HasWebPermission(uri))
                        {
                            throw new InvalidOperationException(SR.GetString(SR.XmlDataSource_NoWebPermission, uri.PathAndQuery, ID));
                        }
                        // Dependencies are not supported with HTTP URLs
                        cacheDependency = null;
                        // If it is an HTTP URL and we have permissions, get a reader
                        return(XmlUtils.CreateXmlReader(path));
                    }
                }

                // Now see what kind of file-based path it is
                VirtualPath virtualPath;
                string      physicalPath;
                ResolvePhysicalOrVirtualPath(path, out virtualPath, out physicalPath);

                if (virtualPath != null && DesignMode)
                {
                    // This exception should never be thrown - the designer always maps paths
                    // before using the runtime control.
                    throw new NotSupportedException(SR.GetString(SR.XmlDataSource_DesignTimeRelativePathsNotSupported, ID));
                }

                Stream dataStream = OpenFileAndGetDependency(virtualPath, physicalPath, out cacheDependency);
                return(XmlUtils.CreateXmlReader(dataStream));
            }
            else
            {
                // Dependencies are not supported with inline content
                cacheDependency = null;
                content         = content.Trim();
                if (content.Length == 0)
                {
                    return(null);
                }
                else
                {
                    return(XmlUtils.CreateXmlReader(new StringReader(content)));
                }
            }
        }
Esempio n. 2
0
 private XmlReader GetReader(string path, string content, out CacheDependency cacheDependency)
 {
     if (path.Length != 0)
     {
         Uri         uri;
         VirtualPath path2;
         string      str;
         if (Uri.TryCreate(path, UriKind.Absolute, out uri) && (uri.Scheme == Uri.UriSchemeHttp))
         {
             if (!HttpRuntime.HasWebPermission(uri))
             {
                 throw new InvalidOperationException(System.Web.SR.GetString("XmlDataSource_NoWebPermission", new object[] { uri.PathAndQuery, this.ID }));
             }
             cacheDependency = null;
             if (AppSettings.RestrictXmlControls)
             {
                 return(new NoEntitiesXmlReader(path));
             }
             return(new XmlTextReader(path));
         }
         base.ResolvePhysicalOrVirtualPath(path, out path2, out str);
         if ((path2 != null) && base.DesignMode)
         {
             throw new NotSupportedException(System.Web.SR.GetString("XmlDataSource_DesignTimeRelativePathsNotSupported", new object[] { this.ID }));
         }
         Stream datastream = base.OpenFileAndGetDependency(path2, str, out cacheDependency);
         if (AppSettings.RestrictXmlControls)
         {
             return(new NoEntitiesXmlReader(datastream));
         }
         return(new XmlTextReader(datastream));
     }
     cacheDependency = null;
     content         = content.Trim();
     if (content.Length == 0)
     {
         return(null);
     }
     if (AppSettings.RestrictXmlControls)
     {
         return(new NoEntitiesXmlReader(new StringReader(content)));
     }
     return(new XmlTextReader(new StringReader(content)));
 }