Content Studio is a platform that gives developers great freedom to develop web sites. The whole .NET platform and the internal API can be used together with Master pages and user controls. This section will describe some standard programming techniques.

Page directives

Page directives is a new feature in Content Studio 5 that regulates the instructions used by the page and user control compilers when they process ASP.NET Web Forms page (.aspx) and user control (.ascx) files. There are several types of directives each one regulates a specific processing option. For example the Page directive specifies the programming language (C# or Visual Basic .NET) that the asp.NET code is written in.

Directives can occur anywhere in a file but in Content Studio they are always placed on the top of the page. Here is a typical example:

<% @Page Language="C#" AutoEventWireup="true" %>

In Content Studio most of the directives can be handled in the Directives dialog that provides a visual interface to most of the supported directives in

The page directive dialog

The following directives are supported in ASP.NET.

Directive name Description


Defines page-specific attributes used by the ASP.NET page parser and compiler. Can be included only in .aspx files.


Defines control-specific attributes used by the ASP.NET page parser and compiler. Can be included only in .ascx files (user controls).


Explicitly imports a namespace into a page or user control.


Declaratively indicates that a page or user control implements a specified .NET Framework interface.


Associates aliases with namespaces and class names, thereby allowing user controls and custom server controls to be rendered when included in a requested page or user control.


Links an assembly to the current page during compilation, making all the assembly's classes and interfaces available for use on the page.


Identifies an ASP.NET master page.


Provides the means to get strong typing against the previous page as accessed through the PreviousPage property.


Assigns a class name to the Master property of an ASP.NET page, so that the page can get strongly typed references to members of the master page.


Declaratively controls the output caching policies of a page or user control.


Declaratively links a page or user control to the current page or user control.

In Content Studio 5.4 the Implements, MasterType, WebHandler and PreviousPageType directives are not supported.

Server side validation

When updating EPT documents you can specify the server should validate the content saved in a certain field. In the Content Studio interface the author of the editing template can specify what content a certain field may contain, (for example fields could be set up to only allow email addresses or number). If enabled Content Studio will guarantee that the field has a format that meets the requirements before any content can be saved to that document.

There is also a built in support for custom validators, but currently there is no interface in Content Studio to activate them. This functionality will be added later.

One advantage with server side validation is that documents cannot be changed in any way if they break the validating rule regardless of the type of client that performs the upgrade. Validation rules are no longer dependent on code written in ASPX-code or in script code in the Web browser.

Calling a Web API from a Javascript

Vid kommunikation med Content Studios API med JavaScript från klientsidan används Content Studio Web API. Content Studio Web API är en uppsättning web handlers (webbsidor med filändelsen .ashx) som kapslar in klasser och metoder i Content Studio API. Filerna fungerar som vanliga aspx-sidor och exekverar .NET-kod när de anropas.

Anrop till CS API från Javascript används exempelvis i AJAX-lösningar för att fylla dropdown-listor eller utföra andra dynamiska anrop mot CS. Content Studio använder Web API:et i administrationsgränssnittet. Förutom Web API tillhandahåller Content Studio en uppsättning web services som kapslar in CS API. Det är möjligt att anropa CS Web Services från JavaScript men den här guiden riktar sig mot CS Web API.


Anrop till CS Web API görs via HTTP och de tar emot argument som skickas in via querystrings och/eller postning och som svar returnerar de XML. CS Web API ligger i Admin-katalogen på den plats Content Studio installerats.

Sökvägen är [Content Studio Admin]\WebAPI\. Eftersom filerna ligger i CS Admin-katalog delas API:et mellan samtliga webbplatser på CS Servern.

Filerna har en namngivningskonvention som överensstämmer med den plats klasserna ligger i Content Studio API. De har namnen [Namespace]_[Namespace]_.._[Klass].ashx, exempelvis ContentStudio_Document_EPT_XmlIndexQuery.ashx som kapslar in metodanrop i en klass som ligger i namespacet ContentStudio.Document.EPT och har klassnamnet XmlIndexQuery.

Http-sökväg för samma fil blir http://[url till server]/cs/WebAPI/ContentStudio_Document_EPT_XmlIndexQuery.ashx

Eftersom filerna ligger i admin är de skyddade av NT-inloggning, det krävs en inloggning för att anropa en fil. Anrop till CS Web API bör därför endast göras i från sidor som kräver inloggning i CS, exempelvis redigeringsformulär. Är avsikten att göra anrop i från en publik sida som ej kräver inloggning bör inte CS Web API anropas direkt utan istället en sida som anropar den avsedda metoden på serversidan i .NET.

Anropa CS Web API

Alla Web API:er tar emot två querystrings; ConnectionID och action.

Web API:erna tar emot olika parametrar, vissa tar emot postat data andra inte, men alla har querystrings som är obligatoriska: ConnectionID är den unika identifieraren för varje Content Studio sajt på en server. Action beskriver vilken operation som ska utföras.

Generellt så används querystrings som parametrar för enskilda värden som exempelvis PageNo, PageSize, ConnectinID, Id m.m. Vid större datamängder och dynamisk input används postat data.


Exemplet anropar query-metoden på klassen XmlIndexQuery, ConnectionID är 1. Metoden gör en filtrering på EPT-kategorin med kategori id 197.

Url: ContentStudio_Document_EPT_XmlIndexQuery.ashx?action=query&ConnectionID=1

Postat data

    <parameter name="categoryID">197</parameter>
    <parameter name="f1">CS_Document_Title</parameter>
    <parameter name="filter">[CS_Document_Title] = 'rubrik'</parameter>


Http-anrop görs i Javascript med ett XmlHttp-objekt. Först måste ett sådant skapas. Beroende webbläsare används olika funktioner för att skapa upp objektet.

var xmlHttp;
if (window.XMLHttpRequest)
   xmlHttp=new XMLHttpRequest();
else if (window.ActiveXObject)
   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

Open förbereder för anropet. Den tar i det här fallet tre argument: action - POST eller GET, url - sökväg och om anropet ska köras asynkront, d.v.s. om koden ska fortsätta att köras och i så fall anropa ett en bestämd funktion när svar kommer, eller synkront - vänta med att fortsätta exekvera kod tills dess att anropet är gjort. I det här exemplet görs ett synkront anrop. Action är POST eftersom data ska postas in.

Send gör anropet. Argumentet anger data som ska postas till mottagaren.

var url = "http://[url till server]/cs/WebAPI/ContentStudio_Document_EPT_XmlIndexQuery.ashx?action=query&ConnectionID=1";"POST", url, false); 

Svar från servern kan man läsa ut från responseText och responseXml.


Se programexempel "Calling CS Web API from JavaScript". Se Web API referens för en beskrivning av alla Web API:er.

Calling web services

Calling a regular web service from within ASP.NET requires proxy classes that encapsulate the logic.

In Visual Studio these classes are created automatically when adding a new web reference to your project. In Content Studio these proxy classes can be created using the WSDL tool included in .NET framework. After creating the proxy class file you can either compile the class file to a .DLL library or import the content of the class file to Content Studio by creating a new code file in the System/App_Code Content Studio folder.

Creating the proxy class

The instructions below can be performed on any computer that has the .NET Framework 2.0 or 3.0 SDK or Visual Studio 2005 installed. Start a new command window and navigate to the folder where you like the proxy class file to be created.

For the .NET Framework tools to function properly, you must set your Path, Include, and Lib environment variables correctly. Set these environment variables by running SDKVars.bat, which is located in the \v2.0\Bin directory. SDKVars.bat must be executed in every command shell.

Assuming that your Web Service can be found at
you can use the following command to create the proxy class:

Wsdl.exe /language:CS ""

This will create the file MyService.cs in the current directory.

Now you have two options:
You can compile the class file into a .DLL library that you can upload into the System/Assemblies folder in Content Studio. The following command will compile the file into a library (it is also necessary to include the System.Xml.dll and System.Web.Services.dll assemblies):
csc /out:MyService.dll /t:library /r:System.XML.dll /r:System.Web.Services.dll MyService.cs 

Finally, upload the generated assembly (MyService.dll) into the System/Assemblies folder in Content Studio.
You can create a new code file, named MyService in the System/App_Code/CSCode folder in Content Studio and insert the content of the proxy class file. When finished you must Approve the new code file.

The outcome of these two methods is equivalent, since the code automatically is included in the code that is running on the server.

Calling the web service

Provided that all went well so far, you now are ready to consume the web service directly from your Content Studio page. You call the web service as any ordinary .NET object. Thus, if your web service contains the method GetData, you can use the following code: C#

MyService ms = new MyService(); 
string data = ms.GetData();
Dim MyService As New MyService()
Dim data As String = ms.GetData()