Skip to content

User Data

You can store custom data on a channel instance. The IChannel interface exposes a Data property, which is essentially a case-insensitive string dictionary. Data stored in this dictionary is available for the entire lifetime of the channel.

Important

Data stored is not persisted across channel reconnections. If a channel is closed, the data will be lost.

public class SampleIdentityHandler : ChannelHandler<IdentityInformation>
{
    public override Task ExecuteAsync( IChannelContext context, IdentityInformation data, CancellationToken cancellationToken )
    {
        if ( !IsAuthorized( data ) )
        {
            return context.Channel.CloseAsync();
        }

        /*
        store channel-specific user data
        */
        context.Channel.Data["uuid"] = data.UUId;

        return Task.CompletedTask;
    }
}

Note

The Data property is a case-insensitive dictionary. For example, channel.Data["uuid"] is equivalent to channel.Data["UUID"].