Example #1
0
        private SiteMapNode GetNodeFromXmlNode(XmlNode xmlNode, Queue queue)
        {
            SiteMapNode node = null;
            // static nodes
            string title = null, url = null, description = null, roles = null, resourceKey = null;

            // Url attribute is NOT required for a xml node.
            HandlerBase.GetAndRemoveStringAttribute(xmlNode, "url", ref url);
            HandlerBase.GetAndRemoveStringAttribute(xmlNode, "title", ref title);
            HandlerBase.GetAndRemoveStringAttribute(xmlNode, "description", ref description);
            HandlerBase.GetAndRemoveStringAttribute(xmlNode, "roles", ref roles);
            HandlerBase.GetAndRemoveStringAttribute(xmlNode, "resourceKey", ref resourceKey);

            // Do not add the resourceKey if the resource is not valid.
            if (!String.IsNullOrEmpty(resourceKey) &&
                !ValidateResource(ResourceKey, resourceKey + ".title"))
            {
                resourceKey = null;
            }

            HandlerBase.CheckForbiddenAttribute(xmlNode, _securityTrimmingEnabledAttrName);

            NameValueCollection resourceKeyCollection = null;
            bool allowImplicitResourceAttribute       = String.IsNullOrEmpty(resourceKey);

            HandleResourceAttribute(xmlNode, ref resourceKeyCollection,
                                    "title", ref title, allowImplicitResourceAttribute);
            HandleResourceAttribute(xmlNode, ref resourceKeyCollection,
                                    "description", ref description, allowImplicitResourceAttribute);

            ArrayList roleList = new ArrayList();

            if (roles != null)
            {
                int foundIndex = roles.IndexOf('?');
                if (foundIndex != -1)
                {
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Auth_rule_names_cant_contain_char,
                                           roles[foundIndex].ToString(CultureInfo.InvariantCulture)), xmlNode);
                }

                foreach (string role in roles.Split(_seperators))
                {
                    string trimmedRole = role.Trim();
                    if (trimmedRole.Length > 0)
                    {
                        roleList.Add(trimmedRole);
                    }
                }
            }
            roleList = ArrayList.ReadOnly(roleList);

            String key = null;

            // Make urls absolute.
            if (!String.IsNullOrEmpty(url))
            {
                // URL needs to be trimmed. VSWhidbey 411041
                url = url.Trim();

                if (!UrlPath.IsAbsolutePhysicalPath(url))
                {
                    if (UrlPath.IsRelativeUrl(url))
                    {
                        url = UrlPath.Combine(HttpRuntime.AppDomainAppVirtualPathString, url);
                    }
                }

                // VSWhidbey 418056, Reject any suspicious or mal-formed Urls.
                string decodedUrl = HttpUtility.UrlDecode(url);
                if (!String.Equals(url, decodedUrl, StringComparison.Ordinal))
                {
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Property_Had_Malformed_Url, "url", url), xmlNode);
                }

                key = url.ToLowerInvariant();
            }
            else
            {
                key = Guid.NewGuid().ToString();
            }

            // attribute collection does not contain pre-defined properties like title, url, etc.
            ReadOnlyNameValueCollection attributeCollection = new ReadOnlyNameValueCollection();

            attributeCollection.SetReadOnly(false);
            foreach (XmlAttribute attribute in xmlNode.Attributes)
            {
                string value = attribute.Value;
                HandleResourceAttribute(xmlNode, ref resourceKeyCollection, attribute.Name, ref value, allowImplicitResourceAttribute);
                attributeCollection[attribute.Name] = value;
            }
            attributeCollection.SetReadOnly(true);

            node          = new SiteMapNode(this, key, url, title, description, roleList, attributeCollection, resourceKeyCollection, resourceKey);
            node.ReadOnly = true;

            foreach (XmlNode subNode in xmlNode.ChildNodes)
            {
                if (subNode.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                queue.Enqueue(node);
                queue.Enqueue(subNode);
            }

            return(node);
        }
Example #2
0
 /// <summary>
 /// Initialize new instance of the <see cref="DataUri"/> class by using the media type and parameters.
 /// </summary>
 /// <param name="mediaType">The media type of the data uri.</param>
 /// <param name="parameters">The parameters of the data uri.</param>
 protected DataUri(string mediaType, NameValueCollection parameters)
 {
     MediaType   = string.IsNullOrEmpty(mediaType) ? DefaultMediaType : mediaType;
     _parameters = parameters == null ? new ReadOnlyNameValueCollection(StringComparer.CurrentCultureIgnoreCase) : new ReadOnlyNameValueCollection(parameters);
     _parameters.SetReadOnly();
 }
Example #3
0
        private SiteMapNode GetNodeFromXmlNode(XmlNode xmlNode, Queue queue)
        {
            SiteMapNode node = null;
            string      val  = null;
            string      str2 = null;
            string      str3 = null;
            string      str4 = null;
            string      str5 = null;

            System.Web.Configuration.HandlerBase.GetAndRemoveStringAttribute(xmlNode, "url", ref str2);
            System.Web.Configuration.HandlerBase.GetAndRemoveStringAttribute(xmlNode, "title", ref val);
            System.Web.Configuration.HandlerBase.GetAndRemoveStringAttribute(xmlNode, "description", ref str3);
            System.Web.Configuration.HandlerBase.GetAndRemoveStringAttribute(xmlNode, "roles", ref str4);
            System.Web.Configuration.HandlerBase.GetAndRemoveStringAttribute(xmlNode, "resourceKey", ref str5);
            if (!string.IsNullOrEmpty(str5) && !this.ValidateResource(base.ResourceKey, str5 + ".title"))
            {
                str5 = null;
            }
            System.Web.Configuration.HandlerBase.CheckForbiddenAttribute(xmlNode, "securityTrimmingEnabled");
            NameValueCollection collection = null;
            bool allowImplicitResource     = string.IsNullOrEmpty(str5);

            this.HandleResourceAttribute(xmlNode, ref collection, "title", ref val, allowImplicitResource);
            this.HandleResourceAttribute(xmlNode, ref collection, "description", ref str3, allowImplicitResource);
            ArrayList list = new ArrayList();

            if (str4 != null)
            {
                int index = str4.IndexOf('?');
                if (index != -1)
                {
                    object[] args = new object[] { str4[index].ToString(CultureInfo.InvariantCulture) };
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Auth_rule_names_cant_contain_char", args), xmlNode);
                }
                foreach (string str6 in str4.Split(_seperators))
                {
                    string str7 = str6.Trim();
                    if (str7.Length > 0)
                    {
                        list.Add(str7);
                    }
                }
            }
            list = ArrayList.ReadOnly(list);
            string key = null;

            if (!string.IsNullOrEmpty(str2))
            {
                str2 = str2.Trim();
                if (!System.Web.Util.UrlPath.IsAbsolutePhysicalPath(str2))
                {
                    if (System.Web.Util.UrlPath.IsRelativeUrl(str2))
                    {
                        str2 = System.Web.Util.UrlPath.Combine(HttpRuntime.AppDomainAppVirtualPathString, str2);
                    }
                    if (HttpContext.Current != null)
                    {
                        str2 = HttpContext.Current.Response.ApplyAppPathModifier(str2);
                    }
                }
                string b = HttpUtility.UrlDecode(str2);
                if (!string.Equals(str2, b, StringComparison.Ordinal))
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Property_Had_Malformed_Url", new object[] { "url", str2 }), xmlNode);
                }
                key = str2.ToLowerInvariant();
            }
            else
            {
                key = Guid.NewGuid().ToString();
            }
            ReadOnlyNameValueCollection attributes = new ReadOnlyNameValueCollection();

            attributes.SetReadOnly(false);
            foreach (XmlAttribute attribute in xmlNode.Attributes)
            {
                string text = attribute.Value;
                this.HandleResourceAttribute(xmlNode, ref collection, attribute.Name, ref text, allowImplicitResource);
                attributes[attribute.Name] = text;
            }
            attributes.SetReadOnly(true);
            node = new SiteMapNode(this, key, str2, val, str3, list, attributes, collection, str5)
            {
                ReadOnly = true
            };
            foreach (XmlNode node2 in xmlNode.ChildNodes)
            {
                if (node2.NodeType == XmlNodeType.Element)
                {
                    queue.Enqueue(node);
                    queue.Enqueue(node2);
                }
            }
            return(node);
        }
Example #4
0
 public void Configure(string configFilePath)
 {
     string keyAttriuteName = "key", valueAttributeName = "value";
     Check.IsNotEmpty(configFilePath, "configFilePath");
     configFilePath=Util.GetFullPath(configFilePath);
     if (!File.Exists(configFilePath))
     {
         throw new FileNotFoundException(String.Format(AppCommon.File_Not_Found, configFilePath));
     }
     ConfigXmlDocument document1 = new ConfigXmlDocument();
     try
     {
         document1.Load(configFilePath);
     }
     catch (XmlException exception1)
     {
         throw new ConfigurationErrorsException(exception1.Message, exception1, configFilePath, exception1.LineNumber);
     }
     XmlNode section = document1.DocumentElement;
     _locker.EnterWriteLock();
     try
     {
         _readonlyCollection = new ReadOnlyNameValueCollection(StringComparer.OrdinalIgnoreCase);
         HandlerBase.CheckForUnrecognizedAttributes(section);
         foreach (XmlNode node1 in section.ChildNodes)
         {
             if (!HandlerBase.IsIgnorableAlsoCheckForNonElement(node1))
             {
                 if (node1.Name == "add")
                 {
                     string text1 = HandlerBase.RemoveRequiredAttribute(node1, keyAttriuteName);
                     string text2 = HandlerBase.RemoveRequiredAttribute(node1, valueAttributeName, true);
                     HandlerBase.CheckForUnrecognizedAttributes(node1);
                     _readonlyCollection[text1] = text2;
                 }
                 else
                 {
                     if (node1.Name == "remove")
                     {
                         string text3 = HandlerBase.RemoveRequiredAttribute(node1, keyAttriuteName);
                         HandlerBase.CheckForUnrecognizedAttributes(node1);
                         _readonlyCollection.Remove(text3);
                         continue;
                     }
                     if (node1.Name.Equals("clear"))
                     {
                         HandlerBase.CheckForUnrecognizedAttributes(node1);
                         _readonlyCollection.Clear();
                         continue;
                     }
                     HandlerBase.ThrowUnrecognizedElement(node1);
                 }
             }
         }
         _readonlyCollection.SetReadOnly();
     }
     finally
     {
         _locker.ExitWriteLock();
     }
     FileWatchHandler fileWatchHandler = new FileWatchHandler(this, new FileInfo(configFilePath));
     fileWatchHandler.StartWatching();
 }