如何使sitecore显示图像(或其他资源)

我使用本指南安装了干净的Sitecore 6.6并启用了MVC支持。 所以我的环境是Sitecore 6.6,ASP .NET MVC 3和Razor,Microsoft SQL Server Express 2012,IIS 7.5,我正在使用Microsoft Visual Studio 2012 Express for Web。 我有以下代码:

@Model.PageItem.Fields["Title"];
@Model.PageItem.Fields["Image"].GetValue(true, true);
@Model.PageItem.Fields["Text"];
Sitecore.Data.Items.MediaItem item = Model.PageItem.Fields["Image"].Item; @Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(item));

结果很简单:

 Sitecore  

Welcome to Sitecore

/sitecore/shell/~/media/110D559FDEA542EA9C1C8A5DF7E70EF9.ashx

当我导航到最后一行中指定的路径时,我得到以下错误:

 HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. 

我试了几件事,例如:

  1. Web.config中的Media.UseItemPaths更改为trye(或false) – 没有任何作用…
  2. Web.config中的Media.RequestExtension设置为空(默认为ashx)
  3. 我已经在Web.config中添加了ashx到Allowed扩展(因为如果我不能正常扩展,我至少想要有工作的ashx链接)
  4. 我已将ashx添加到IIS 7.5 – >请求筛选 – >文件扩展名

当然在每次更改后(以防万一)我重新启动服务器并清除了浏览器的缓存(实际上,在几次请求之后我已禁用了chrome的缓存)。

我一直在寻找sdn.sitecore.net上的解决方案而没有运气。 实际上我到目前为止花了3个多小时寻找解决方案,无法弄清楚出了什么问题…任何帮助或建议表示赞赏!

Sitecore.Mvc.Helpers.SitecoreHelper类的Field方法将允许您输出Image字段。

以下是输出三个字段的View Rendering示例:

 @using Sitecore.Mvc.Presentation @using Sitecore.Mvc @model RenderingModel @Html.Sitecore().Field("Title")
@Html.Sitecore().Field("Image")
@Html.Sitecore().Field("Text")

John West在Sitecore MVC上发表了大量博客,您可能希望通过Sitecore ASP.NET CMSpost查看他的关于MVC助手的内容。