Exemplo n.º 1
0
        static Type MapTagType(Type tagType)
        {
            if (tagType == null)
            {
                return(null);
            }

            PagesSection ps = WebConfigurationManager.GetSection("system.web/pages") as PagesSection;

            if (ps == null)
            {
                return(tagType);
            }

            TagMapCollection tags = ps.TagMapping;

            if (tags == null || tags.Count == 0)
            {
                return(tagType);
            }

            string    tagTypeName = tagType.ToString();
            Type      mappedType, originalType;
            string    originalTypeName = String.Empty, mappedTypeName = String.Empty;
            bool      missingType;
            Exception error;

            foreach (TagMapInfo tmi in tags)
            {
                error        = null;
                originalType = null;

                try {
                    originalTypeName = tmi.TagType;
                    originalType     = HttpApplication.LoadType(originalTypeName);
                    if (originalType == null)
                    {
                        missingType = true;
                    }
                    else
                    {
                        missingType = false;
                    }
                } catch (Exception ex) {
                    missingType = true;
                    error       = ex;
                }
                if (missingType)
                {
                    throw new HttpException(String.Format("Could not load type {0}", originalTypeName), error);
                }

                if (originalTypeName == tagTypeName)
                {
                    mappedTypeName = tmi.MappedTagType;
                    error          = null;
                    mappedType     = null;

                    try {
                        mappedType = HttpApplication.LoadType(mappedTypeName);
                        if (mappedType == null)
                        {
                            missingType = true;
                        }
                        else
                        {
                            missingType = false;
                        }
                    } catch (Exception ex) {
                        missingType = true;
                        error       = ex;
                    }

                    if (missingType)
                    {
                        throw new HttpException(String.Format("Could not load type {0}", mappedTypeName),
                                                error);
                    }

                    if (!mappedType.IsSubclassOf(originalType))
                    {
                        throw new ConfigurationErrorsException(
                                  String.Format("The specified type '{0}' used for mapping must inherit from the original type '{1}'.", mappedTypeName, originalTypeName));
                    }

                    return(mappedType);
                }
            }

            return(tagType);
        }
Exemplo n.º 2
0
        internal static long GetRecompilationHash(PagesSection ps)
        {
            HashCodeCombiner combiner = new HashCodeCombiner();

            combiner.AddObject(ps.Buffer);
            combiner.AddObject(ps.EnableViewState);
            combiner.AddObject(ps.EnableViewStateMac);
            combiner.AddObject(ps.EnableEventValidation);
            combiner.AddObject(ps.SmartNavigation);
            combiner.AddObject(ps.ValidateRequest);
            combiner.AddObject(ps.AutoEventWireup);
            if (ps.PageBaseTypeInternal != null)
            {
                combiner.AddObject(ps.PageBaseTypeInternal.FullName);
            }
            if (ps.UserControlBaseTypeInternal != null)
            {
                combiner.AddObject(ps.UserControlBaseTypeInternal.FullName);
            }
            if (ps.PageParserFilterTypeInternal != null)
            {
                combiner.AddObject(ps.PageParserFilterTypeInternal.FullName);
            }
            combiner.AddObject(ps.MasterPageFile);
            combiner.AddObject(ps.Theme);
            combiner.AddObject(ps.StyleSheetTheme);
            combiner.AddObject(ps.EnableSessionState);
            combiner.AddObject(ps.CompilationMode);
            combiner.AddObject(ps.MaxPageStateFieldLength);
            combiner.AddObject(ps.ViewStateEncryptionMode);
            combiner.AddObject(ps.MaintainScrollPositionOnPostBack);
            NamespaceCollection namespaces = ps.Namespaces;

            combiner.AddObject(namespaces.AutoImportVBNamespace);
            if (namespaces.Count == 0)
            {
                combiner.AddObject("__clearnamespaces");
            }
            else
            {
                foreach (NamespaceInfo info in namespaces)
                {
                    combiner.AddObject(info.Namespace);
                }
            }
            TagPrefixCollection controls = ps.Controls;

            if (controls.Count == 0)
            {
                combiner.AddObject("__clearcontrols");
            }
            else
            {
                foreach (TagPrefixInfo info2 in controls)
                {
                    combiner.AddObject(info2.TagPrefix);
                    if ((info2.TagName != null) && (info2.TagName.Length != 0))
                    {
                        combiner.AddObject(info2.TagName);
                        combiner.AddObject(info2.Source);
                    }
                    else
                    {
                        combiner.AddObject(info2.Namespace);
                        combiner.AddObject(info2.Assembly);
                    }
                }
            }
            TagMapCollection tagMapping = ps.TagMapping;

            if (tagMapping.Count == 0)
            {
                combiner.AddObject("__cleartagmapping");
            }
            else
            {
                foreach (TagMapInfo info3 in tagMapping)
                {
                    combiner.AddObject(info3.TagType);
                    combiner.AddObject(info3.MappedTagType);
                }
            }
            return(combiner.CombinedHash);
        }