标签:
[HubName("djwChat")] public class ChatHub:Hub { public void Send(string name) { //动态表达式 Clients.All.addMsgToPage(name); } }
owin配置非常重要。
[assembly: OwinStartup(typeof(SingalRTest.Startup))] namespace SingalRTest { public class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } } }
<appSettings> <add key="webpages:Version" value="2.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="PreserveLoginUrl" value="true" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> <add key="owin:AppStartup" value="SingalRTest.Startup, SingalRTest" /> <!--<add key="owin:AutomaticAppStartup" value="true" />--> </appSettings>
如果没有
[assembly: OwinStartup(typeof(SingalRTest.Startup))],需要在appSettings里配置节点
$(function () { //创建代理 var chat = $.connection.djwChat; chat.client.addMsgToPage = function () { //2、服务端通知客户端 do something }; $("#send").click(function () { chat.server.send("msg"); //1、发送消息到服务端,调用服务端的Send方法 }); $.connection.hub.start(); });
标签:
原文地址:http://www.cnblogs.com/tgdjw/p/4609051.html