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?
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).
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)?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With