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) { // 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); }
// Return the key used to cache the output private string GetCacheKey() { // Create a cache key by combining various elements HashCodeCombiner combinedHashCode = new HashCodeCombiner(); // Start with the guid combinedHashCode.AddObject(_guid); // Make the key vary based on the type of the writer (ASURT 118922) HttpBrowserCapabilities browserCap = Context.Request.Browser; if (browserCap != null) { combinedHashCode.AddObject(browserCap.TagWriter); } // If there are no vary params, we're done with the key if (_varyByParamsCollection == null && _varyByControlsCollection == null && _varyByCustom == null) { return(combinedHashCode.CombinedHashString); } // Get the request value collection NameValueCollection reqValCollection = Page.RequestValueCollection; // If it's not set, get it based on the method if (reqValCollection == null) { reqValCollection = Page.GetCollectionBasedOnMethod(); } if (_varyByParamsCollection != null) { ICollection itemsToUseForHashCode; // If '*' was specified, use all the items in the request collection. // Otherwise, use only those specified. if (_varyByParamsCollection.Length == 1 && _varyByParamsCollection[0] == "*") { itemsToUseForHashCode = reqValCollection; } else { itemsToUseForHashCode = _varyByParamsCollection; } // Add the items and their values to compute the hash code foreach (string varyByParam in itemsToUseForHashCode) { combinedHashCode.AddCaseInsensitiveString(varyByParam); string val = reqValCollection[varyByParam]; if (val != null) { combinedHashCode.AddObject(reqValCollection[varyByParam]); } } } if (_varyByControlsCollection != null) { // Prepend them with a prefix to make them fully qualified string prefix = NamingContainer.UniqueID; if (prefix != null) { prefix += Control.ID_SEPARATOR; } prefix += _ctrlID + Control.ID_SEPARATOR; // Add all the relative vary params and their values to the hash code foreach (string varyByParam in _varyByControlsCollection) { string temp = prefix + varyByParam; combinedHashCode.AddCaseInsensitiveString(temp); string val = reqValCollection[temp]; if (val != null) { combinedHashCode.AddObject(reqValCollection[temp]); } } } if (_varyByCustom != null) { string customString = Context.ApplicationInstance.GetVaryByCustomString( Context, _varyByCustom); if (customString != null) { combinedHashCode.AddObject(customString); } } return(combinedHashCode.CombinedHashString); }