【发布时间】:2014-03-20 20:23:40
【问题描述】:
我在一个使用 signalr 的网站上工作,当我在本地机器上测试它时它工作正常,但是当我远程尝试它时,我无法浏览 mvc,当我尝试向 signalar 发送请求时它就坐在那里等待。
这是我的 javascript 代码(我正在使用 angularjs,但所有代码都可以正常工作!):
function FixturesListController($scope,$q) {
$scope.fixtures = [''];
var stringListHub = $.connection.stringListHub,
model = {
Items: []
};
$.connection.hub.url = "http://192.168.1.2:8001/signalr";
stringListHub.client.updateModel = function(newName) {
if (newName.Items != null) {
$scope.$apply(function() {
$scope.fixtures.length = 0;
$(newName.Items).each(function(index, value) {
$scope.fixtures.push(value);
});
});
}
}
$.connection.hub.start({ xdomain: true }).done(function () {
var fixtures = stringListHub.server.test().done(function (item) {
$scope.$apply(function () {
if (item.Items != null) {
$scope.fixtures.length = 0;
$(item.Items).each(function(index, value) {
$scope.fixtures.push(value);
});
}
});
});
});
$scope.AddFixture = function() {
$scope.fixtures.push($scope.newName);
stringListHub.server.updateModel({
Items: $scope.fixtures
});
};
}
这里是信号器集线器:
public class StringListHub : Hub
{
private static StringList _list = new StringList();
public void UpdateModel( StringList model )
{
_list = model;
_list.LastUpdatedBy = Context.ConnectionId;
// Update the shape model within our broadcaster
Clients.AllExcept( _list.LastUpdatedBy ).updateModel( _list );
}
public StringList Test()
{
return _list;
}
}
我将此添加到我的 web.config 中
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
【问题讨论】:
-
“无法浏览MVC”,这是什么意思?您是否收到任何错误消息?
-
您是否使用过 Fiddler 或 Firebug 之类的工具来查看是否有返回的响应错误代码或 javacript 错误?
-
是的,已经尝试了所有这些,并且无法浏览 mvc,我的意思是它只是坐在那里加载,没有任何反应
-
您能否启用客户端日志记录并将开发人员控制台的输出复制到您的问题中? asp.net/signalr/overview/signalr-20/hubs-api/… "xdomain: true" 什么都不做。如果要开启跨域访问,需要在服务器上进行:asp.net/signalr/overview/signalr-20/hubs-api/…
标签: c# .net iis-7.5 signalr signalr-hub