Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDL Tridion C# code fragment can't find engine, package or log fields in context

Tags:

c#

tridion

I'm quite new to Tridion development and I'm having my first "basic" issue. I've written a simple C# code fragment in a TBB (using content manager text editor) and I've tried to use engine, package and log fields (as I know they are made available by Tridion) but I receive an error saying "the name does not exist in context". Here is the code:

<%@ 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();
%>

When I save the TBB and publish the page I receive this error:

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 

Probably I miss something or do something wrong, does anyone recognize the problem?

like image 793
BitRider Avatar asked Dec 09 '22 19:12

BitRider


2 Answers

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).

like image 191
Frank van Puffelen Avatar answered Dec 11 '22 10:12

Frank van Puffelen


You can find information on how to properly create a C# fragment at How to add user defined methods in C# TBB(C# code fragment)?

like image 31
Jeremy Grand-Scrutton Avatar answered Dec 11 '22 12:12

Jeremy Grand-Scrutton