rdb: How to integrate ASP.NET into RedDot CMS projects – Best practice on .NET template embedding

Is it easy to integrate .NET into your RedDot CMS project? Yes it is, if you know how and obey some simple rules. This article gives you a best practice on how to include any .NET functionality for your published website within your RedDot CMS templates.

If you can avoid using inline code within your RedDot Content Classes then do it

Inline code within a content class can’t be versioned as it could be with a version control system when developing standard .NET solutions outside of any CMS. You can’t develop or test properly using inline code within the CMS. Whenever you have to change the .NET part of your project you would need a RedDot Consultant or some of their knowledge and hence your project doubles up on resources. Don’t integrate inline code within your CMS. 

Let the CMS handle content – Don’t care about the rest

There is a clear understanding of what your CMS should handle for you – your content – and what it should not take care of – styling and dynamic functionality may it be Javascript, .NET or any other scripting technology. The CMS is your data storage and management layer, the web server is your presentation and visualization layer and hence it is the point where dynamic functionality, styling and user interaction takes place. By keeping those parts separate you ensure to have a stable, scalable and furthermore easily maintain- and upgradeable Content Management Solution.

Example – How to integrate .Net properly using User Controls

Instead of just adding a page directive followed by your inline code you should use user controls. Given that your code will be used on your website and not within the Open Text CMS ASP.NET User Controls are the best way to embedded dynamic functionality within your project.
There are basically two points where .NET is included in your template. The first one needs to be in every template which uses User Controls unless you integrate it using a container. The second one works as placeholder for the .NET functionality:

1. Reference the .ascx file at the very top of the template

 RenderTags & .NET C# 
<reddot:cms><if><query valuea="Context:CurrentRenderMode" operator="==" valueb="Int:2"><htmltext>
<%@ page language="C#" %>
<%@ Register Src="~/UserControls/Search.ascx" TagName="Search" TagPrefix="uc" %>

This example references a code behind file for a search used on the web server. It is placed in the top of every page instance created with this template. This way you only have to integrate the .NET reference once in each template. You can break it down to once per project if you use a container approach.

2. Place the User control tags as placeholder for the .NET functionality

 RenderTags & .NET C# 
  <div id="site">
    <div id="header">
<reddot:cms><if><query valuea="Context:CurrentRenderMode" operator="==" valueb="Int:2"><htmltext>
      <uc:Search ID="Search" runat="Server"/>

This is the ASP.NET User Control for your search interface. Since you don’t run the search inside of your CMS project we have used a Render Tag to exclude this block from showing up within the CMS. If you want to be fancy you can put some placeholder content here by using a different Context:CurrentRenderMode block where you use valuea=”Context:CurrentRenderMode” operator=”<>” valueb=”Int:2″ to show HTML code only on the CMS server, you can read more about this here

Maintain & edit your ASP.NET code outside of the CMS

By following the example above whenever you have to update your .NET code you just have to change your .ascx file, there is no need to touch or even deploy the .ascx file to the CMS server. There is an approach of using the built-in .Net folder within RedDot CMS but since you might as well just upload your files manually I dare to say – Why bother? Ok, you should bother in a clustered server system where you publish to multiple publishing targets, but for a simple one CMS one web server setup you might as well just stick to manual deployments.

Changing ASP.NET properties and influencing your .NET from within the CMS

In RedDot we are able to insert User Control tag into any area of a page. If you have to influence settings or content areas you can use several ways to generate content and integrate those within .Net applications. You can use XML files published by RedDot CMS or user attributes with inline edited content to changed and/or edit properties. Those can be passed through to your User Controls. No need to use the CMS as IDE for your .NET solutions, keep all parts of your project separate and everything is just fine.