Generates an HTTP/1.1 Cache header Entity Tag (ETag)
HTTP/1.1 RFC: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.26 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.25 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.29
Exemplo n.º 1
0
        /// <summary>
        /// Sets ETag.Value
        /// </summary>
        /// <param name="Entity"></param>
        protected virtual string CalculateETag()
        {
            bool   isHash;
            object metaData = this.GetMetaData(out isHash);

            string etag;

            if (metaData is Guid)
            {
                etag = ((Guid)metaData).ToString("N");
            }
            else if (metaData is string)
            {
                if (isHash)
                {
                    etag = (string)metaData;
                }
                else
                {
                    etag = ETag.ComputeHash((string)metaData);
                }
            }
            else if (metaData is byte[])
            {
                if (isHash)
                {
                    etag = ETag.FormatBytes((byte[])metaData);
                }
                else
                {
                    etag = ETag.ComputeHash((byte[])metaData);
                }
            }
            else if (metaData is Stream)
            {
                etag = ETag.ComputeHash((Stream)metaData);
            }
            else
            {
                throw new NotSupportedException("GetMetaData must return Guid, String, Byte[], or Stream");
            }

            return("\"" + etag + "\"");
        }