【问题标题】:How can I make sitecore showing an image (or other resources)如何让 sitecore 显示图像(或其他资源)
【发布时间】:2013-02-08 05:43:38
【问题描述】:

我安装了干净的 Sitecore 6.6 并使用此 guide 启用了 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"];<br />
@Model.PageItem.Fields["Image"].GetValue(true, true);<br />
@Model.PageItem.Fields["Text"];<br />
Sitecore.Data.Items.MediaItem item = Model.PageItem.Fields["Image"].Item;
@Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(item));<br />

结果很简单:

Sitecore
<image mediaid="{4DFD3ABC-0BC0-41D2-BD38-705946A1368A}" mediapath="/Images/xbox" src="~/media/4DFD3ABC0BC041D2BD38705946A1368A.ashx" />
<p>Welcome to Sitecore</p> 
/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. 我已将 ashx 添加到 Web.config 中的允许扩展(因为如果我不能拥有正常的扩展,我至少希望有工作 ashx 链接)
  4. 我已将 ashx 添加到 IIS 7.5 -> 请求过滤 -> 文件扩展名

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

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

【问题讨论】:

    标签: c# .net sitecore sitecore6


    【解决方案1】:

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

    这是一个输出三个字段的视图渲染示例:

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

    John West 曾在 Sitecore MVC 上发表过大量博客,您不妨看看他的 About MVC Helpers with the Sitecore ASP.NET CMS 帖子。

    【讨论】:

    • @Html.Sitecore().Field("Image") 完成了这项工作!非常感谢凯文 - 我不知道为什么你的代表点数比我少......
    猜你喜欢
    • 1970-01-01
    • 2011-05-01
    • 1970-01-01
    • 2021-06-18
    • 1970-01-01
    • 2013-08-13
    • 2022-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多