本文介绍了Sitecore-2个媒体项目.相同的文件名,不同的扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有2个名称相同但扩展名不同的媒体项目,则Sitecore无法区分它们.

If you have 2 media items that have the same name but different extensions, Sitecore cannot differentiate between them.

例如:

/〜/media/myfile.文档

/~/media/myfile.doc

当请求这些URL时,在两种情况下都将返回PDF文件.

When these URL's are requested, the PDF file is returned in both cases.

我知道Sitecore会忽略请求中的扩展名,而真正的问题实际上是,我在媒体库中本质上有两个具有相同路径的项目:

I understand that that Sitecore ignores the extension in the request, and that the real problem is in fact, that I essentially have two items with the same path in the media library:

但是,我认为我们的客户希望将同一文档的PDF和DOC版本都存储在一个节点中是合理的.

However, I do think it's a reasonable that our customer would want to store both PDF and DOC versions of the same document in a single node.

我发现本文解决了确保所请求的媒体项目文件扩展名有效的相关问题:

I found this article which addresses the related problem of ensuring that the requested media item file extension is valid:

http://www .cognifide.com/blogs/sitecore/sitecore-serves-media-items-even-with-incorrect-extensions/

但是,这仍然基于您首先获得正确的Sitecore项的前提(对于请求myfile.doc而言并非如此).

However, this is still based on the premise that you have obtained the correct Sitecore item in the first place (which isn't true in the case of the request for myfile.doc).

所以我想我的问题是,是否有一种方法可以防止Sitecore仅获取找到的第一个项目并考虑扩展名.

So I guess my question is whether there is a way prevent Sitecore from simply getting the first item it finds and to take the extension into account.

推荐答案

如果请求的资源是媒体项目,则可以覆盖web.config中的媒体提供程序或项目解析器:

You can possibly override either the media provider or the item resolver in the web.config and if the requested resource is a media item:

  1. 看看它是否有同名的兄弟姐妹
  2. 如果是这样,请检查请求的扩展名(doc,PDF等)
  3. 根据扩展名找到具有该类型的同级并将其返回.

这篇关于Sitecore-2个媒体项目.相同的文件名,不同的扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 19:18