4

As with all media files in Sitecore the extension is converted to .ashx which is proving to be a problem for the visitors to my site when using IE and acrobat reader. Basically the user clicks the download link, the current page loads indicating that something is about to happen but then nothing opens. Would I be correct in saying that Adobe Acrobat is having trouble with the .ashx extension when it is looking for .pdf so it just gives up? If this is the case then how can I get around it?

Kyle

styler
  • 15,779
  • 23
  • 81
  • 135

3 Answers3

5

I believe this may be a common problem. What version of Sitecore are you using? There are various discussions of this on the SDN:

I would check you MIME types as mentioned in the first link above.

Mark Ursino
  • 31,209
  • 11
  • 51
  • 83
2

Just a side note:

Firefox for Mac has a general problem handling .ashx files directly (ie linking to them directly).

This is usually something that is seen with PDFs, as that will try to open the .ashx file og not check the content disposition.

Be aware of problems with Firefox on a Mac, as PDFs wont seem to work there.

For that you need to setup some stuff according to:

http://sdn.sitecore.net/scrapbook/media%20files%20downloaded%20with%20ashx%20extension.aspx

if you can't access that is basically tells you to go to the web.config, find this:

<mediaType name="PDF file" extensions="pdf">

and change the

<forceDownload>false</forceDownload>

to

<forceDownload>true</forceDownload>
Holger
  • 2,243
  • 17
  • 19
2

true will force any type of browser to download the pdf...

Here is the ultimate solution:

make a C# class

public class MediaHandler : MediaRequestHandler
{
    public override void ProcessRequest(HttpContext context)
    {

        DeterminePDFRequest(context);

        base.ProcessRequest(context);

    }

    private static void DeterminePDFRequest(HttpContext context)
    {

        MediaRequest request = MediaManager.ParseMediaRequest(context.Request);

        if (request != null)
        {
            Media media = MediaManager.GetMedia(request.MediaUri);

            if (media != null)
            {
                Item item = media.MediaData.MediaItem;
                MediaItem mediaItem = media.MediaData.MediaItem;

                if (mediaItem != null)
                {

                    if (context.Request.UserAgent != null)
                    {
                        if (mediaItem.Extension != "pdf")
                            return;

                        string requestedUrl = context.Items["SC_REQUEST_MEASUREMENT_URL"].ToString();

                        if (!requestedUrl.Contains(".pdf"))
                        {

                            MediaUrlOptions mediaUrlOptions = new MediaUrlOptions
                            {
                                AbsolutePath = true,
                                DisableMediaCache = true,
                                DisableBrowserCache = true
                            };

                            string url = StringUtil.EnsurePrefix('/',
                                                                MediaManager.GetMediaUrl(mediaItem,
                                                                                        mediaUrlOptions));
                            url = url.Replace(".ashx", ".pdf");
                            QueryString queryString = new QueryString(url);
                            context.Response.Redirect(queryString.All);
                        }
                    }
                }
            }
        }
    }
}

make sure to replace and update verb="*" path="sitecore_media.ashx" in web.config to use your MediaHandler

James Skemp
  • 8,018
  • 9
  • 64
  • 107