blaster
blaster

Reputation: 8937

SignalR - Preserve Same Connection Across Multiple Pages of Web Application

I'd like to provide a user experience where a SignalR connection is available across multiple pages in my ASP.NET MVC application.

If I include SignalR startup code (JS) in my _Layout.cshtml, will that be perceived by the server as a "fresh" client connection every time the user navigates to a different page? Or will SignalR support this kind of behavior out of the box?

Upvotes: 4

Views: 1860

Answers (1)

N. Taylor Mullen
N. Taylor Mullen

Reputation: 18301

Each page is represented as a "Client" so therefore you will have a unique connection per page (no way around that). Alternatives to this issue are:

  1. Dynamically load pages and display them on current page. Essentially only having one physical page.
  2. Save user state in a cookie or session and when you start a new connection fill it with your saved state. Be wary of security issues with this approach.

Hope this helps!

Upvotes: 5

Related Questions