Get Started!

Visitor's Session Data

Sometime you'll want to record session based data, canvas has a dedicated Session object that allows you to attach any type of data to for the period of the visitors session. It also contains references to User information.

The oUser property

Every Canvas ASCX control has a property oSession, which it-self has a property oUser of type Net4orce.Canvas.Data.Users.User.

Every request made by a visitor has an object oSession.oUser set.

Non-Authenticated Users

Non-Authenticated users have an instance of User defined. It's role, oSession.oUser.cRole with be set to Guest. Meaning that oSession.oUser.HasAdmin() will not error, but will return false, as they are a Guest.

Authenticated Users

If a visitor logs in, the User details are set in oSession.oUser. Exposing their name, email address, role etc.

Testing User Roles

You can test the role of a user via some extension methods. We used extension methods to allow developers to extend the range of roles beyond the defaults.

To use the built-in role in the Code-Behind for an ASCX C# you must import the namespace Net4orce.Core.Data.Users via :

using Net4orce.Core.Data.Users;

Or, in the ASCX HTML

<%@ Import Namespace="Net4orce.Core.Data.Users" %>

This allows you to then test the different roles.

Test for Member Level

if( oSession.oUser.HasMember() ){
  // Has at least Member level access

Test for Author Level

if( oSession.oUser.HasAuthor() ){
  // Has at least Author level access

Test for Admin Level

if( oSession.oUser.HasAdmin() ){
  // Has at least Admin level access

Test for SuperAdmin Level

if( oSession.oUser.HasSuperAdmin() ){
  // Has at least SuperAdmin level access

Custom Session Data

You could use the session object directly, via Session[SOME_KEY] but this tends to require additional logic to test for the key ect.

Instead Canvas exposes another object, built-on the session state, that makes attaching data, of any type, to a session a peice of cake.

Setting some Session Data

The Session object has a method, SetGeneric for setting a session value that can recieve any type of object.


This stores the object someObject in the session for the visitor, using the key some-key as an identifier for retrival.

Retriving the Stored Session Data

To retrive some data from the session the method GetGeneric<T> is used.

Assuming the type of someObject in the example above was MyType it can be retrivied using :

var someObject = oSession.GetGeneric<MyType>(

The GetGeneric<T> method handles the testing of the object's existance, casts it's type to MyType and returns it.