Код на стороне сервера
public void NotifyPermissionOfficeUpdate(string staffId)
{
var updater = GlobalHost.ConnectionManager.GetHubContext("HubVersion");
if (updater != null)
updater.Clients.All.officePermissionChanged(staffId);
}
Код на стороне клиента
<!--Script references. -->
<!--Reference the jQuery library. -->
<script src="Scripts/jquery-1.10.2.min.js"></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.4.1.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="Scripts/signalRserver.js"></script>
<!--Add script to update the page and send messages.-->
<script type="text/javascript">
$(function () {
var connection = $.hubConnection('/siukservice/signalr', {useDefaultPath: false});
var updater = connection.createHubProxy('hubVersion');
updater.on('versionChanged', function(version) {
var encodedName = "ahmed:";
var encodedMsg = $('<div />').text(version).html();
$('#discussion').append('<li><strong>' + encodedName
+ '</strong>: ' + encodedMsg + '</li>');
});
updater.on('officePermissionChanged', function (version) {
var encodedName = "ahmed:";
var encodedMsg = $('<div />').text(version).html();
$('#discussion').append('<li><strong>' + encodedName
+ '</strong>: ' + encodedMsg + '</li>');
});
connection.start({ withCredentials: false })
.done(function () {
$('#sendmessage').click(function () {
// Call the Send method on the hub.
updater.server.notifyPermissionOfficeUpdate( $('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
console.log('Now connected, connection ID=' + connection.id);
})
.fail(function(){ console.log('Could not connect'); });
});
</script>
Сообщение об ошибке в браузере Теперь подключено, идентификатор подключения = 9b5ec23f-5c96-4f17-8eca-1e2da5b9ecbd 8signalRTest. html: 50 Uncaught TypeError: Невозможно прочитать свойство notifyPermissionOfficeUpdate из undefined