SignalR拒绝工作 [英] SignalR refuses to work
本文介绍了SignalR拒绝工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapConnection<myconnection>("echo", "echo/{*operation}");
}
myconnection.cs
public class myconnection : PersistentConnection
{
protected override Task OnReceivedAsync(string clientId, string data)
{
// Broadcast data to all clients
return Connection.Broadcast(data);
}
}
〜/页/ Messages.aspx
<script src="http://code.jquery.com/jquery-1.7.min.js" type="text/javascript"></script>
<script src="../Scripts/jquery.signalR.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var connection = $.connection('echo');
connection.received(function (data) {
$('#messages').append('<li>' + data + '</li>');
});
connection.start();
$("#broadcast").click(function () {
connection.send($('#msg').val());
});
});
</script>
<input type="text" id="msg" />
<input type="button" id="broadcast" value="broadcast" />
<ul id="messages">
</ul>
错误:
SignalR:连接必须启动数据可以发送之前。之前。发送调用。开始()()
ERROR:
SignalR: Connection must be started before data can be sent. Call .start() before .send()
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
</configuration>
<script type="text/javascript" src='<%= ResolveClientUrl("~/signalr/hubs") %>'></script>
这两种解决方案(https://github.com/SignalR/SignalR/wiki/Faq)并没有解决我的问题。 有任何想法吗)?谢谢你。
Both solutions (https://github.com/SignalR/SignalR/wiki/Faq) did not fix my issue. Any idea(s)? Thanks.
推荐答案
请确保您正确配置的URL 回声
脚本:
Make sure that you properly configure the url to the echo
script:
var connection = $.connection('<%= ResolveClientUrl("~/echo") %>');
既然你是里面的〜/页
文件夹中使用回声
不正确,因为你的路由预计 /回声
或 /应用程序的名字/回声
如果应用程序托管在一个虚拟目录中。
Since you are inside the ~/Pages
folder using echo
is incorrect because your routing expects /echo
or /appname/echo
if the application is hosted inside a virtual directory.
这篇关于SignalR拒绝工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文