There is apparently no way to know which page is open by a particular user.
As someone said on a forum
How would the server know if HTML code is "opened" in a browser?
I couldn't find a solution, so I chose to do it differently.
All the code for SignalR is placed in the Layout.
Upon receiving a message, I want to know if the recipient is currently checking their messages or not.
I create a condition with an element of the document that only exists on the messaging page.
connection.on("ReceiveMessage", function(userexp, userdest, topic, message, refresh_status) {
var contf = document.querySelector(".fiche"); // fiche only exists on my "Messaging" page
if(contf != null)
{
//code for the Messaging page
}
else
{
//code for any other page (Notification PopUp in main menu)
}
Consequently, by also placing the notification message template in the _Layout, I can notify the user at any time and anywhere on the site.