4

我对 Tridion 开发很陌生,我遇到了第一个“基本”问题。我已经在 TBB 中编写了一个简单的 C# 代码片段(使用内容管理器文本编辑器),并且我尝试使用引擎、包和日志字段(因为我知道它们由 Tridion 提供)但我收到一条错误消息“该名称在上下文中不存在”。这是代码:

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" %>
<div>
        <!-- TemplateBeginRepeat name="Component.Fields.crociera" -->
              <!-- TemplateBeginIf cond="prezzo<250" -->
                     Go to @@location@@<br/>
              <!-- TemplateEndIf -->
        <!-- TemplateEndRepeat -->
</div>
<%
String ts = DateTime.Now.ToString("d MMM yyyy");
Response.Write("<br/>"+ts);
engine.getSession();
%>

当我保存 TBB 并发布页面时,我收到此错误:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0103: The name 'engine' does not exist in the current context

Source Error:


Line 31: Response.Write("<br/>"+ts);
Line 32: engine.getSession();
Line 33: %>                         
Line 34:                  </div>

Source File: c:\inetpub\wwwroot\stage\pj\ricerca\ricerca.aspx    Line: 32 

可能我错过了什么或做错了什么,有人认识到这个问题吗?

4

2 回答 2

11

The Engine object you use is part of Tridion's TOM.NET API, which is only available to your code while the item is being published.

Once the ASPX page reaches the front-end server, the TOM.NET API is not available anymore. Part of the reason for this is that the Tridion Content Manager is simply not reachable from your web server anymore.

Instead of programming against the Tridion Content Manager through its TOM.NET API, you need to program against Tridion Content Delivery through its API. You can find the documentation for common cases in the Live Docs (log in required).

于 2012-11-07T11:25:20.833 回答
3

您可以在如何在 C# TBB(C# 代码片段)中添加用户定义的方法中找到有关如何正确创建 C# 片段的信息?

于 2012-11-07T11:00:00.373 回答