【发布时间】:2016-06-01 03:47:54
【问题描述】:
我正在尝试使用Monodevelop 设置SignalR 项目。我通过Nuget 安装了SignalR 软件包,一切都编译了,但是当我点击我的页面时,我不断收到cannot read property of undefined。
我无法弄清楚我缺少什么,此时我想我可能缺少配置文件。
这是我所拥有的:
// the view
@section scripts {
<script src="~/Scripts/jquery-2.2.3.min.js"></script>
<script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="~/signalr/hubs" type="text/javascript"></script>
<!--SignalR script to update the chat page and send messages.-->
<script>
$(function () {
// Reference the auto-generated proxy for the hub.
var chat = $.connection.chatHub;
// Create a function that the hub can call back to display messages.
console.log(chat);
chat.client.addNewMessageToPage = function (name, message) {
// Add the message to the page.
console.log('here');
$('#discussion').append('<li><strong>' + htmlEncode(name)
+ '</strong>: ' + htmlEncode(message) + '</li>');
};
// Get the user name and store it to prepend to messages.
$('#displayname').val(prompt('Enter your name:', ''));
// Set initial focus to message input box.
$('#message').focus();
// Start the connection.
$.connection.hub.start().done(function () {
$('#sendmessage').click(function () {
// Call the Send method on the hub.
chat.server.send($('#displayname').val(), $('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
});
});
// This optional function html-encodes messages for display in the page.
function htmlEncode(value) {
var encodedValue = $('<div />').text(value).html();
return encodedValue;
}
</script>
}
~/signalr/hubs 似乎没有 404,但是当我在 chrome 中预览上下文时,那里什么也没有。这是一个空文件,这可能是一切的根本原因。
这是启动文件。我在configuration 方法中设置了一个断点,它确实命中了该代码。
using System;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(SignalRChat.Startup))]
namespace SignalRChat
{
public class Startup
{
public Startup ()
{
}
public void Configuration (IAppBuilder app)
{
app.MapSignalR ();
}
}
}
这里是枢纽:
using System;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
namespace SignalRChat
{
[HubName("chatHub")]
public class ChatHub : Hub
{
public void Send (string name, string message)
{
Clients.All.addNewMessageToPage (name, message);
}
public ChatHub ()
{
}
}
}
编辑:在 IIS 服务器上的 Visual Studios 上运行此代码,一切正常。我认为这可能是mono 的特定问题。我添加了标签。
【问题讨论】:
-
您使用的是哪个版本的 Mono? (
mono --version) -
我正在使用版本
4.2.3 -
执行文件夹中有哪些 SignalR DLL? (我必须同时使用
Microsoft.AspNet.SignalR.Core.dll和Microsoft.AspNet.SignalR.SystemWeb.dll) -
我同时拥有
Microsoft.AspNet.SignalR.Core.Dll、Microsoft.AspNet.SignalR.SystemWeb.dll