Generates an ETag for a specific Guid.
상속: ETag
예제 #1
0
        /// <summary>
        /// Determines the appropriate source for the incomming request
        /// </summary>
        /// <param name="context"></param>
        /// <param name="isDebug"></param>
        /// <returns>CompiledBuildResult</returns>
        protected virtual IOptimizedResult GetResourceInfo(HttpContext context, bool isDebug)
        {
            string           virtualPath = context.Request.AppRelativeCurrentExecutionFilePath;
            IOptimizedResult info        = ResourceHandler.Create <IOptimizedResult>(virtualPath);

            if (info == null)
            {
                throw new HttpException(404, "Resource not found: " + virtualPath);
            }

            // check if client has cached copy
            ETag etag = new HashETag(info.Hash);

            if (etag.HandleETag(context, HttpCacheability.ServerAndPrivate, isDebug))
            {
                return(null);
            }

            return(info);
        }
예제 #2
0
        public override void ExecuteResult(ControllerContext context)
        {
            HttpResponseBase response = context.HttpContext.Response;

            try
            {
                response.ClearHeaders();
                response.ClearContent();
            }
            catch { }

            response.TrySkipIisCustomErrors = true;

            if (this.Resource == null)
            {
                response.ContentType = "text/plain";
                response.StatusCode = (int)HttpStatusCode.NotFound;
                response.Write(response.Status);
                return;
            }

            HttpContext httpContext = HttpContext.Current;

            // check if client has cached copy
            ETag etag = new HashETag(this.Resource.Hash);
            if (etag.HandleETag(httpContext, HttpCacheability.ServerAndPrivate, this.IsDebug))
            {
                return;
            }

            if (String.IsNullOrEmpty(this.Resource.ContentType))
            {
                response.ContentType = "text/plain";
            }
            else
            {
                response.ContentType = this.Resource.ContentType;
            }

            // this helps IE determine the Content-Type
            // http://tools.ietf.org/html/rfc2183#section-2.3
            ContentDisposition disposition = new ContentDisposition
            {
                Inline = !this.IsAttachment,
                FileName =
                    String.IsNullOrEmpty(this.Filename) ?
                    Path.GetFileNameWithoutExtension(this.ResourcePath)+'.'+this.Resource.FileExtension :
                    this.Filename
            };
            response.AddHeader("Content-Disposition", disposition.ToString());

            ResourceHandler.WriteResponse(httpContext, this.Resource, this.IsDebug);
        }