ice.NET Web SDK
The ice.NET Web SDK (the part of the SDK that is contained in the PDTec.IceNet.Web
assembly) provides base classes and utilities to develop ASP.NET-based web applications
(HTML/Ajax applications or Web Services) with ice.NET functionality in a consistent and
efficient way. Technical aspects such as database configuration, repository access and
HTTP request lifecycle are handled by platform components.
Infrastructure
The centerpiece of the ice.NET Web SDK is the IceNetHttpApplication base class.
This class provides the connection between the ASP.NET-based presentation logic and
the ice.NET-based business logic. The ASP.NET application requires a global application
class (Global.asax) derived from IceNetHttpApplication. There are two possibilities
to define this global application class:
Global.asax without code-behind file (e.g. for ASP.NET Web Sites):
<%@ Application Language="C#" Inherits="PDTec.IceNet.Web.IceNetHttpApplication" %>
Global.asax.cs code-behind file (e.g. for ASP.NET MVC or WebForms Applications):
public class Global : PDTec.IceNet.Web.IceNetHttpApplication
{
...
To establish the connection to the ice.NET infrastructure, especially the database,
a few entries in the application configuration file are required.
web.config:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="ice.net" type="PDTec.IceNet.Sdk.ConfigSectionHandler,PDTec.IceNet.Sdk"/>
</configSections>
<ice.net>
<database service="Sql2005" connectionString="server=(local)\SQLEXPRESS;trusted_connection=yes;database=my_ice_db" encrypted="false" />
<license path="..\license.xml"/>
</ice.net>
<system.web>
[...]
</system.web>
</configuration>
The IceNetHttpApplication class provides access to the
ice.NET infrastructure through the static Current property:
- IceNetHttpApplication.Current.Repository - the central entry point for ice.NET model and data.
- IceNetHttpApplication.Current.IceNetUserName - the currently active user.
To simplify the development of ASP.NET applications, ice.NET provides base classes for
all major ASP.NET component categories that directly provide the Repository and
IceNetUserName properties:
- IceNetWebPage
- IceNetWebControl
- IceNetWebUserControl
- IceNetWebService
- IceNetHttpHandler
Programming Example
The following example demonstrates how to access the ice.NET Repository
from an ASP.NET page. Therefore we create a WebPage and change the superclass.
Default.aspx.cs:
public partial class _Default : IceNetWebPage
{
...
Next, we declare some static ASP.NET markup to display an HTML bulleted list.
Default.aspx:
<h1>ice.NET Packages:</h1>
<asp:BulletedList ID="aspListPackages" runat="server" />
Finally, we access the ice.NET repository from the Page_Load event,
retrieve the list of all model packages from the database and add the
package names to the ASP.NET list control.
Default.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
IPackage[] aPackages = Repository.GetPackages();
foreach (IPackage pPackage in aPackages)
{
aspListPackages.Items.Add(new ListItem(pPackage.Name));
}
}