Exemple #1
0
        public void ProcessRequest(HttpContext context)
        {
            var theme = Convert.ToString(_requestContext.RouteData.Values.ValueOrDefault(ResourceRoute.ThemeRouteDictionaryKey));

            if (theme == ResourceRoute.DefaultThemePlaceholder)
            {
                theme = null;
            }

            var rname    = _requestContext.RouteData.Values.ValueOrDefault(ResourceRoute.ResourceNameRouteDictionaryKey) as string;
            var resource = string.IsNullOrEmpty(rname) ?
                           ResourceRouteHandler.ResourceDescription.Empty :
                           _routeHandler.GetResource(rname, theme);
            var res = GetContent(context, resource);

            if (res == null)
            {
                context.Response.StatusCode        = 404;
                context.Response.StatusDescription = "Not Found. Make sure your resource file has a build action of 'Embedded Resource'";
                context.Response.Write("Unable to find resource " + rname + ". Make sure your resource file has a build action of 'Embedded Resource'");
                return;
            }

            var ims = IfModifiedSinceBinder.ParseHeader(context.Request);

            if (ims != null && (res.LastModified - ims.Value).TotalSeconds < 1)
            {
                context.Response.StatusCode        = 304;
                context.Response.StatusDescription = "Not Modified";
                return;
            }

            context.Response.StatusCode        = 200;
            context.Response.StatusDescription = "OK";
            context.Response.ContentType       = MimeType.FromFileName(rname);
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.Cache.SetLastModified(res.LastModified);
            context.Response.BinaryWrite(res.Content);
        }
 public StaticContentResult(byte[] uncompressedContent, string fileName)
 {
     this.FileName     = fileName;
     this.ContentType  = MimeType.FromFileName(fileName);
     this.Uncompressed = uncompressedContent;
 }
        } //RegisterQuickLinks

        public static string Base64Data(EmbeddedFileEntity file)
        {
            return("data:" + MimeType.FromFileName(file.FileName) + ";base64," + Convert.ToBase64String(file.BinaryFile));
        } //Base64Data