Book Image

SignalR Real-time Application Cookbook

By : Roberto Vespa
Book Image

SignalR Real-time Application Cookbook

By: Roberto Vespa

Overview of this book

Table of Contents (18 chapters)
SignalR Real-time Application Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Handling a connection transient state


In the previous recipe, we talked about how a persistent connection can experience problems that SignalR tries to fix automatically. We also saw that such a logical connection is represented by a unique identifier, which is lost when SignalR is not able to recover from underlying failures anymore. As long as the persistent connection is alive, SignalR offers a simple way to associate some transient state to it in the form of a property bag that can be read and written on both the client and server side. For simple scenarios, where we want to maintain some information associated with each connection and use it on both sides to adjust the behavior of available methods/callbacks, this API can be quite useful. The usual scenarios could be related to classical cross-cutting concerns (authorization and logging), but it could be used for anything.

In this recipe, we'll build a simple case where we maintain a transient property called name, and we manipulate...