User Data
You can store custom ephemeral data on a channel instance. The IChannel interface exposes a Data property, which is essentially a case-insensitive, thread-safe dictionary. Data stored in this dictionary is available for the entire lifetime of the channel and is automatically discarded when the channel closes.
Important
Channel data is ephemeral and is not persisted across reconnections. If a channel is closed, all associated data is 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"].