Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jo Kendal 32 posts 194 karma points
    Sep 05, 2016 @ 13:58
    Jo Kendal
    0

    ProcessRequest fails to fire

    Hi

    Since upgrading to Umbraco 7.5.2 from 7.2.8 the file handlers I had in place have stopped firing.

    I can see nothing wrong in the code or config files.

    Can anyone shed any light on what the issue may be?

    Config file:

    <add name="DOCX" path="*.docx" verb="*" type="FileHandler"/> 
    <add name="XLSX" path="*.xlsx" verb="*" type="FileHandler"/> 
    <add name="DOC" path="*.doc" verb="*" type="FileHandler"/> 
    <add name="XLS" path="*.xls" verb="*" type="FileHandler"/> 
    <add name="PDF" path="*.pdf" verb="*" type="FileHandler"/> 
    <add name="MP3" path="*.mp3" verb="*" type="FileHandler"/> 
    

    FileHandler.cs in App_Code directory

    namespace myUmbracoApp.App_Code
    

    { public class FileHandler : IHttpHandler {

        public FileHandler()
        {
        }
    
        bool IHttpHandler.IsReusable
        {
            get { return false; }
        }
    
        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            switch (context.Request.HttpMethod)
            {
                case "GET":
                    {
                        // Is the user logged-in? 
                        if (!context.User.Identity.IsAuthenticated)
                        {
                            System.Web.HttpContext.Current.Response.Redirect("/");
                            return;
                        }
    
                        string requestedFile = context.Server.MapPath(context.Request.FilePath);
    
                        SendContentTypeAndFile(context, requestedFile);
    
                        break;
                    }
            }
        }
    
    
        HttpContext SendContentTypeAndFile(HttpContext context, String strFile)
        {
            context.Response.ContentType = GetContentType(strFile);
            context.Response.TransmitFile(strFile);
            context.Response.End();
    
            return context;
        }
    
        public string GetContentType(string filename)
        {
            // used to set the encoding for the reponse stream 
            string res = null;
            FileInfo fileinfo = new FileInfo(filename);
    
            if (fileinfo.Exists)
            {
                switch (fileinfo.Extension.Remove(0, 1).ToLower())
                {
                    case "pdf":
                        {
                            res = "application/pdf";
                            break;
                        }
                    case "doc":
                        {
                            res = "application/msword";
                            break;
                        }
                    case "docx":
                        {
                            res = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                            break;
                        }
                    case "xls":
                        {
                            res = "application/vnd.ms-excel";
                            break;
                        }
                    case "xlsx":
                        {
                            res = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                            break;
                        }
                    case "mp3":
                        {
                            res = "audio/mpeg";
                            break;
                        }
                }
    
                return res;
            }
    
            return null;
        }
    
    }
    

    }

  • Jo Kendal 32 posts 194 karma points
    Sep 07, 2016 @ 09:13
    Jo Kendal
    100

    For those who may be experiencing the same issue I found a web.config in the media folder. I added my handler config into this web.config and now my handler fires OK.

  • Jo Kendal 32 posts 194 karma points
    Sep 21, 2016 @ 09:27
    Jo Kendal
    0

    I have posted an article on resolving this issue and writing the handler itself. See here for more: https://www.steadygo.digital/blog/securing-media-files-umbraco-7-5-2/

Please Sign in or register to post replies

Write your reply to:

Draft