Sunday 15 May 2011

asp.net mvc - SignalR 2 does not generate /signalr/hubs -



asp.net mvc - SignalR 2 does not generate /signalr/hubs -

here page:

<script src="~/scripts/jquery-1.10.2.min.js"></script> <script src="~/scripts/jquery.signalr-2.1.2.min.js"></script> <!--reference autogenerated signalr hub script. --> <script src="~/signalr/hubs"></script> <!--signalr script update chat page , send messages.--> <script> $(function () { // reference auto-generated proxy hub. var notification = $.connection.notificationhub; // create function hub can phone call display messages. notification.client.addnewmessage = function (message) { // add together message page. $('#discussion').append('<li><strong>' + '</strong>: ' + htmlencode(message) + '</li>'); }; // set initial focus message input box. $('#message').focus(); // start connection. $.connection.hub.start().done(function () { $('#sendmessage').click(function () { // phone call send method on hub. chat.server.send($('#message').val()); // clear text box , reset focus next comment. $('#message').val('').focus(); }); }); }); // optional function html-encodes messages display in page. function htmlencode(value) { var encodedvalue = $('<div />').text(value).html(); homecoming encodedvalue; } </script>

here hub class:

using system; using system.collections.generic; using system.linq; using system.web; using microsoft.aspnet.signalr; using microsoft.aspnet.signalr.hubs; namespace adminwebapp.hubs { [hubname("notificationhub")] public class notificationhub : hub { public void sendnotification(string message) { clients.all.addnewmessage(message); } } }

startup.cs:

using microsoft.owin; using owin; [assembly: owinstartupattribute(typeof(adminwebapp.startup))] namespace adminwebapp { public partial class startup { public void configuration(iappbuilder app) { configureauth(app); } } }

when seek access: http://localhost:4551/signalr/hubs http 404 not found error , when seek run page get:

failed load resource: server responded status of 404 (not found) uncaught typeerror: cannot read property 'client' of undefined

i have tried this: signalr : /signalr/hubs not generated , didnt work.

any ideas?

in global.asax file on application_start event have register hub url.

protected void application_start() { routetable.routes.maphubs(); }

asp.net-mvc signalr signalr-hub signalr.client

No comments:

Post a Comment