PDF converted to .ashx in sitecore not opening with IE

Like all media files in Sitecore, the extension is converted to .ashx, which is a problem for 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. Should I be right in saying that Adobe Acrobat is having problems with the .ashx extension when it searches for .pdf, so it just gives up? If so, how can I get around this?

Kyle

+4
source share
3 answers

I think this can be a common problem. What version of Sitecore are you using? There are various discussions in the SDN:

I would look at you MIME types, as mentioned in the first link above.

+5
source

Just a note:

Firefox for Mac has a common problem with processing .ashx files directly (i.e. directly linking to them).

This is usually something that can be seen with PDF files, as it will try to open the .ashx og file without checking the location of the content.

Be aware of problems with Firefox on Mac, as PDF files do not work there.

To do this, you need to configure some things according to:

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

if you cannot access, this basically tells you to go to web.config, find this:

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

and change

 <forceDownload>false</forceDownload> 

to

 <forceDownload>true</forceDownload> 
+2
source

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

Here is the final solution:

make 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); } } } } } } } 

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

+2
source

Source: https://habr.com/ru/post/1345887/


All Articles