Skip to content

User Data

It is possible to 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 throughout the channel's lifetime.

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

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

        return Task.CompletedTask;
    }
}

Note

The Data property is a case-insensitive dictionary. This means that the keys are treated as case-insensitive. For example, channel.Data["uuid"] is the same as channel.Data["UUID"].