Firefox for Mac has a problem handling .ashx for PDF files, Sitecore

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

<handlers>
    <add verb="*" path="sitecore_media.ashx" type="Website.logic.Helper.MediaHandler, Website" name="Sitecore.MediaRequestHandler" />
</handlers>
      
<httpHandlers>
    <add verb="*" path="sitecore_media.ashx" type="Website.logic.Helper.MediaHandler, Website"/>
</httpHandlers>
Advertisements

2 thoughts on “Firefox for Mac has a problem handling .ashx for PDF files, Sitecore

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s