Example #1
0
        private void serveSite(WorkContext work, string sitePath)
        {
            if (sitePath.IsNullOrWhiteSpace())
            {
                sitePath = DefaultSitePath;
            }

            var assembly = this.GetType().Assembly;

            //Cut the surrogate out of path, i.e. '/static/img/@@767868768768/picture.png' -> '/static/img/picture.png'
            sitePath = FileDownloadHandler.CutVersionSegment(sitePath, m_VersionSegmentPrefix);

            var resName = getResourcePath(sitePath);

            var bi           = new BuildInformation(assembly);
            var lastModified = bi.DateStampUTC.DateTimeToHTTPCookieDateTime();

            var ifModifiedSince = work.Request.Headers[SysConsts.HEADER_IF_MODIFIED_SINCE];

            if (ifModifiedSince.IsNotNullOrWhiteSpace() && lastModified.EqualsOrdIgnoreCase(ifModifiedSince))
            {
                SetResourceCacheHeader(work, sitePath, resName);
                work.Response.Redirect(null, WebConsts.RedirectCode.NotModified_304);
                return;
            }
            using (var stream = assembly.GetManifestResourceStream(resName))
                if (stream != null)
                {
                    work.Response.Headers.Set(HttpResponseHeader.LastModified, lastModified);
                    SetResourceCacheHeader(work, sitePath, resName);
                    work.Response.ContentType = mapContentType(resName);

                    stream.Seek(0, SeekOrigin.Begin);
                    work.Response.WriteStream(stream);
                }
                else
                {
                    throw new HTTPStatusException(WebConsts.STATUS_404, WebConsts.STATUS_404_DESCRIPTION, StringConsts.NOT_FOUND_ERROR + resName);
                }
        }