Ejemplo n.º 1
0
        private string ComputeVaryCacheKey(HashCodeCombiner combinedHashCode,
                                           ControlCachedVary cachedVary)
        {
            // Add something to the has to differentiate it from the non-vary hash.
            // This is needed in case this method doesn't add anything else to the hash (VSWhidbey 194199)
            combinedHashCode.AddInt(1);

            // Get the request value collection
            NameValueCollection reqValCollection;
            HttpRequest         request = Page.Request;

            if (request != null && request.HttpVerb == HttpVerb.POST)
            {
                // Bug 6129: Partial cache key should include posted form values in postbacks.
                // Include both QueryString and Form values (but not Cookies or Server Variables like Request.Params does).
                // Per Request.Params behavior, add QueryString values before Form values
                reqValCollection = new NameValueCollection(request.QueryString);
                reqValCollection.Add(request.Form);
            }
            else
            {
                // Use the existing value if possible to avoid recreating a NameValueCollection
                reqValCollection = Page.RequestValueCollection;
                // If it's not set, get it based on the method
                if (reqValCollection == null)
                {
                    reqValCollection = Page.GetCollectionBasedOnMethod(true /*dontReturnNull*/);
                }
            }

            if (cachedVary._varyByParams != null)
            {
                ICollection itemsToUseForHashCode;

                // If '*' was specified, use all the items in the request collection.
                // Otherwise, use only those specified.
                if (cachedVary._varyByParams.Length == 1 && cachedVary._varyByParams[0] == "*")
                {
                    itemsToUseForHashCode = reqValCollection;
                }
                else
                {
                    itemsToUseForHashCode = cachedVary._varyByParams;
                }

                // Add the items and their values to compute the hash code
                foreach (string varyByParam in itemsToUseForHashCode)
                {
                    // Note: we use to ignore certain system fields here (like VIEWSTATE), but decided
                    // not to for consistency with pahe output caching (VSWhidbey 196267, 479252)

                    combinedHashCode.AddCaseInsensitiveString(varyByParam);
                    string val = reqValCollection[varyByParam];
                    if (val != null)
                    {
                        combinedHashCode.AddObject(val);
                    }
                }
            }

            if (cachedVary._varyByControls != null)
            {
                // Prepend them with a prefix to make them fully qualified
                string prefix;
                if (NamingContainer == Page)
                {
                    // No prefix if it's the page
                    prefix = String.Empty;
                }
                else
                {
                    prefix = NamingContainer.UniqueID;
                    Debug.Assert(!String.IsNullOrEmpty(prefix));
                    prefix += IdSeparator;
                }

                prefix += _ctrlID + IdSeparator;

                // Add all the relative vary params and their values to the hash code
                foreach (string varyByParam in cachedVary._varyByControls)
                {
                    string temp = prefix + varyByParam.Trim();
                    combinedHashCode.AddCaseInsensitiveString(temp);
                    string val = reqValCollection[temp];
                    if (val != null)
                    {
                        combinedHashCode.AddObject(reqValCollection[temp]);
                    }
                }
            }

            if (cachedVary._varyByCustom != null)
            {
                string customString = Context.ApplicationInstance.GetVaryByCustomString(
                    Context, cachedVary._varyByCustom);
                if (customString != null)
                {
                    combinedHashCode.AddObject(customString);
                }
            }

            return(CacheInternal.PrefixPartialCachingControl + combinedHashCode.CombinedHashString);
        }
Ejemplo n.º 2
0
        private Control LoadControl(IWebObjectFactory objectFactory, VirtualPath virtualPath, Type t, object[] parameters)
        {
            // Make sure we get an object factory or a type, but not both
            Debug.Assert((objectFactory == null) != (t == null));

            BuildResultCompiledType         compiledUCResult  = null;
            BuildResultNoCompileUserControl noCompileUCResult = null;

            if (objectFactory != null)
            {
                // It can be a compiled or no-compile user control
                compiledUCResult = objectFactory as BuildResultCompiledType;
                if (compiledUCResult != null)
                {
                    t = compiledUCResult.ResultType;
                    Debug.Assert(t != null);

                    // Make sure it's a user control (VSWhidbey 428718)
                    Util.CheckAssignableType(typeof(UserControl), t);
                }
                else
                {
                    noCompileUCResult = (BuildResultNoCompileUserControl)objectFactory;
                    Debug.Assert(noCompileUCResult != null);
                }
            }
            else
            {
                // Make sure the type has the correct base class (ASURT 123677)
                if (t != null)
                {
                    Util.CheckAssignableType(typeof(Control), t);
                }
            }

            PartialCachingAttribute cacheAttrib;

            // Check if the user control has a PartialCachingAttribute attribute
            if (t != null)
            {
                cacheAttrib = (PartialCachingAttribute)
                              TypeDescriptor.GetAttributes(t)[typeof(PartialCachingAttribute)];
            }
            else
            {
                cacheAttrib = noCompileUCResult.CachingAttribute;
            }

            if (cacheAttrib == null)
            {
                // The control is not cached.  Just create it.
                Control c;
                if (objectFactory != null)
                {
                    c = (Control)objectFactory.CreateInstance();
                }
                else
                {
                    c = (Control)HttpRuntime.CreatePublicInstance(t, parameters);
                }

                // If it's a user control, do some extra initialization
                UserControl uc = c as UserControl;
                if (uc != null)
                {
                    Debug.Assert(virtualPath != null);
                    if (virtualPath != null)
                    {
                        uc.TemplateControlVirtualPath = virtualPath;
                    }
                    uc.InitializeAsUserControl(Page);
                }

                return(c);
            }

            HashCodeCombiner combinedHashCode = new HashCodeCombiner();

            // Start by adding the type or object factory of the user control to the hash.
            // This guarantees that two unrelated user controls don't share the same cached data.
            if (objectFactory != null)
            {
                combinedHashCode.AddObject(objectFactory);
            }
            else
            {
                combinedHashCode.AddObject(t);
            }

            // If it's not shared, add some stack frames to the hash
            if (!cacheAttrib.Shared)
            {
                AddStackContextToHashCode(combinedHashCode);
            }

            string cacheKey = combinedHashCode.CombinedHashString;

            // Wrap it to allow it to be cached
            return(new PartialCachingControl(objectFactory, t, cacheAttrib, "_" + cacheKey, parameters));
        }
        private string ComputeVaryCacheKey(HashCodeCombiner combinedHashCode, ControlCachedVary cachedVary)
        {
            combinedHashCode.AddInt(1);
            NameValueCollection requestValueCollection = this.Page.RequestValueCollection;

            if (requestValueCollection == null)
            {
                requestValueCollection = this.Page.GetCollectionBasedOnMethod(true);
            }
            if (cachedVary._varyByParams != null)
            {
                ICollection is2;
                if ((cachedVary._varyByParams.Length == 1) && (cachedVary._varyByParams[0] == "*"))
                {
                    is2 = requestValueCollection;
                }
                else
                {
                    is2 = cachedVary._varyByParams;
                }
                foreach (string str in is2)
                {
                    combinedHashCode.AddCaseInsensitiveString(str);
                    string s = requestValueCollection[str];
                    if (s != null)
                    {
                        combinedHashCode.AddObject(s);
                    }
                }
            }
            if (cachedVary._varyByControls != null)
            {
                string str3;
                if (this.NamingContainer == this.Page)
                {
                    str3 = string.Empty;
                }
                else
                {
                    str3 = this.NamingContainer.UniqueID + base.IdSeparator;
                }
                str3 = str3 + this._ctrlID + base.IdSeparator;
                foreach (string str4 in cachedVary._varyByControls)
                {
                    string str5 = str3 + str4.Trim();
                    combinedHashCode.AddCaseInsensitiveString(str5);
                    if (requestValueCollection[str5] != null)
                    {
                        combinedHashCode.AddObject(requestValueCollection[str5]);
                    }
                }
            }
            if (cachedVary._varyByCustom != null)
            {
                string varyByCustomString = this.Context.ApplicationInstance.GetVaryByCustomString(this.Context, cachedVary._varyByCustom);
                if (varyByCustomString != null)
                {
                    combinedHashCode.AddObject(varyByCustomString);
                }
            }
            return("l" + combinedHashCode.CombinedHashString);
        }
Ejemplo n.º 4
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);
        }