2. Configuration and conventions
2.1 Typical SASP application
A typical SASP application consists out of two projects:
- Website project containing the view files (and possibly special ASP.NET files like web.config or global.asax), we refer to this project as the WebApplication?.
- Control project containing the controller classes (code behind) for both pages, templates and custom controls. This project is usually a class library, we refer to it as the ControllerAssembly?.
Contains view files and special ASP.NET files. Also should contain a specific UserControls? folder that holds the view files for custom controls and templates.
The web.config file must contain a number of a specific SASP related appSettings:
<appSettings>
<!-- Root namespace of the assembly containing the control code -->
<add key="SasControllerAssembly" value="SASP.WebDemo.Control"/>
<!-- Extension of the files containing the view code (xhtml) -->
<add key="SasViewExtension" value=".html"/>
<!-- Folder name of the special folder containing the view files for custom controls -->
<add key="SasControlFolder" value="UserControls"/>
<!-- Set to 1 if SASP should look for view files and class names in a case sensitive manner.
It's usually best to leave this on 1, only on Windows do you have the option to use case insensitivity. -->
<add key="SasCaseSensitive" value="1"/>
<!-- Enable tracing or not, leave this on 0 unless you know what you are doing -->
<add key="SasTrace" value="0"/>
</appSettings>
Also the actual server-side extension must be mapped in the web.config file:
<httpHandlers> <!-- Example where all .ashx files would be handled by SASP --> <add verb="*" path="*.ashx" type="SASP.Core.SasPageHandlerFactory, SASP.Core"/> </httpHandlers>
ControllerAssembly?: The controller assembly must have two subnamespaces:
- Controllers: contains all controller code for the web pages
- Controls: contains all code for possible custom controls
The names of these namespaces are fixed, only the root namespace of the controller assembly can be configured in the web.config file.
Notes:
- The view file extension is arbitrary, it must be a file extension that is mapped to the ASP.NET ddl, and the extension must be defined in the web.config file. For demo applications the extension .ashx is often used since this is a default extension mapped to ASP.NET.
- The special App_Code folder of ASP.NET 2.0 is not supported.
- The UserControls folder is arbitrary, the folder name must be defined in the web.config file.
- The namespace of the ControllerAssembly is arbitrary but must be defined in the web.config file.
2.2 SASP pages
A web page in SASP must adhere to a couple or rules:
- the page must inherit SasPage?
- the page can be only a view file, only a controller class (code behind) or a combination of view + code behind
- the controller namespace structure must match the url request path for SASP to be able to create the controller
- the view folder structure must match the namespace structure for SASP to be able to retrieve the associated view
- the basic namespace of SasPage? instances must be as follows: <assembly>.Controllers.<subnamespace>
Example requests where view files have the extension .htm:
| URL | Controller class | View file |
| http://mywebapp/Index.ashx | MyControlAssembly.Controllers.Index | /Index.htm |
| http://mywebapp/SubFolder/TestPage.ashx | MyControlAssembly.Controllers.SubFolder.TestPage? | /SubFolder/TestPage.htm |
2.3 Custom controls
A custom control in SASP must adhere to a couple of rules:
- the control must inherit SasControl?
- the control can be only a view file, only a control class (code behind) or a combination of view + code behind
- the basic namespace of custom controls must be as follows: <assembly>.Controls.<subnamespace>
All controls must have a folder defined as the root reference for relative control paths. This is also the folder where the view files are stored and is configured in the web.config file by setting the SasControlFolder key.
To use a control in a page, the control must be specified by using the unique control path. A control can be created in code behind by calling the LoadControl? method, or can be used directly in a view file by providing a header directive:
<% PersonInfo : /UserControls/PersonInfo %>
<html>
<head><title>Demo html</title></head>
<body>
This is a custom control: <PersonInfo _id="personInfo" />
</body>
</html>
Example control paths where view files have the extension .htm and the SasControlFolder is set to UserControls?:
| Control path | Control class | View file |
| /UserControls/TestControl | MyControlAssembly.Controls.TestControl? | /UserControls/TestControl.htm |
| /UserControls/Group/MemberCtl | MyControlAssembly.Controls.Group.MemberCtl? | /UserControls/Group/MemberCtl.htm |
2.4 Creating controls from a view
So when does SASP create a server-side control for xml elements? The rule is quite simple, for every (x)(ht)ml element defined in a view file, the framework will create a matching server-side control if any of the following cases apply:
- the element has an id attribute
- the element has an _id or sid attribute
- the element has any attribute that starts with an underscore (see 'Hidden attributes')
An id attribute or any underscore-attribute are called server-side tokens in the SASP view context.
