I have a news site that runs C # ASP.Net MVC 5.0, and I want to push a notification to the client browser when the administrator adds / edits or deletes the news.
so I added a signalr script to my template, which is used on all pages.
_Layout.cshtml
var notificationsHub = $.connection.notificationHub;
$.connection.hub.start();
jQuery(function($) {
notificationsHub.client.Toast = function (title, body) {
var options = {
body: body,
};
var notification = new Notification(title, options);
};
});
and added this code to the page, which is redirected after adding / editing / deleting news.
<script>
$.connection.hub.start().done(function() {
notificationsHub.server.toast('@NotificationHub.Type.ToString()', '@Html.Raw(NotificationHub.Title)', '@Html.Raw(NotificationHub.Body)');
});
</script>
when I add / edit / delete news, it works fine, but the problem is that it causes notifications about all open tabs on my site. Is there a trick to avoid this and show only one browser notification per site?