8

We are using Tridion 2013 and the Razor mediator.

We import Razor Helper Functions in the Tridion.ContentManager.Config file, like so:

<add import="/webdav/xxx Design Master/Building Blocks/System/Templates/TBBs/Razor/Razor Helper Functions.cshtml" />

This works fine when we save a Component Template that references a function in the helper file.

It works fine when we preview a Component Presentation or Page.

However when we publish a page, we get failed status and the following error:

TemplateCompileException: CS0103: The name 'GetPageTitle' does not exist in the current context

We've tried restarting all the Tridion services, IIS and even the server itself.

The publisher is not scaled out, this is an-all-in one development server.

What steps do we need to follow to ensure the imported Razor Helper functions can be picked up by the publisher service?

4
  • 1
    I hate to say this... but how sure are you that it's really the same machine running the publisher? I've seen often (especially in Dev environments) that there would be other servers connecting to the same database. Check QUEUE_CONSUMERS table for the name of servers using this database.
    – Nuno Linhares
    Oct 4, 2013 at 17:49
  • That was also our first thought - so we stopped the Publisher service completely. Jobs sit in the 'waiting for publish state' until we restart.
    – user669
    Oct 4, 2013 at 18:03
  • Sorry then. No clue here, good luck finding it. Might be worth pinging Alex once you do find an answer, since it seems Eric also had the same issue.
    – Nuno Linhares
    Oct 4, 2013 at 18:22
  • 1
    It might help to add an issue here: code.google.com/p/razor-mediator-4-tridion/issues/list Oct 4, 2013 at 21:04

3 Answers 3

9

I had the same issue, I ended by having my custom razor functions in a cshtml file in my .Net Project.

<razor.mediator cacheTime="60" extractBinaries="true" adminUser="Administrator">
..
    <imports>
        <add import="[MyProjectPath]\Functions.cshtml" />
    <imports>
..
</razor.mediator>

I hope this helps.

3
  • Yes, thank-you, i think we are going to have to go down that route for now. Its not great as it means template code is moved out of Tridion - in Tridion 2011 we could reference webdav paths without any issue. I think something must have changed in 2013.
    – user669
    Oct 4, 2013 at 18:14
  • 3
    I have imports for 2013 working with the @importRazor("../relative/webdav/path/here") syntax - it may be a pain to include the import in every TBB that needs it, but its perhaps better than moving all the code out of the CMS.
    – Will Price
    Oct 5, 2013 at 7:57
  • @WillPrice - Thank-you, I tried this but for some reason i'm having exactly the same issue with the importRazor statement. (works fine on save/preview, but publisher doesn't find the helpers) The same helpers referenced the way Eric suggests works fine.
    – user669
    Oct 7, 2013 at 7:41
5

Just in case anyone is still having this problem, I solved it by adding the NT AUTHORITY\SYSTEM account (the account that the Publisher Service runs under by default) as an impersonation user.

This is done in the %TRIDION_HOME%/config/Tridion.ContentManager.config file, and mine now looks as follows:

<impersonationUsers>
    <clear />
    <add name="NT AUTHORITY\NETWORK SERVICE" impersonationType="Windows" />
    <add name="NT AUTHORITY\SYSTEM" impersonationType="Windows" />        
</impersonationUsers>

I restarted the Tridion Windows Services, IIS and the 'SDL Web Content Manager' COM+ item, just for good measure.


Presumably, this is needed because the Publisher needs to impersonate the user that is configured as the adminUser (shown below as DOMAIN\Username) in the <razor.mediator> section of the %TRIDION_HOME%/config/Tridion.ContentManager.config file:

<razor.mediator cacheTime="600" extractBinaries="true" adminUser="DOMAIN\Username">
...
<imports>    
    <add import="/wevdav/020 Design/Building Blocks/System/TBBs/Helpers/razor-helpers.cshtml" />
</imports>
...

0
1

Just check the Windows Event Log for messages related to the inability to import the TBBs. It could be that the user running the publisher service (instead of the MTS user as mentioned in some sources) needs to be The impersonation user...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.