我在尝试使用Monodevelop
设置SignalR
项目。我通过Nuget
安装了SignalR
软件包,并且编译了所有内容,但当我打开我的页面时,我仍然收到cannot read property of undefined
。在MonoDevelop上运行SignalR ChatHub未定义
我无法弄清楚我错过了什么,在这一点上我想我可能会丢失一个配置文件。
这是我有:
// 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,但是当我预览铬的背景下,有什么都没有。这是一个空文件,这可能是一切的根本原因。
这是启动文件。我放了一个断点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服务器上和工作的事情。我认为这可能是mono
的一个特定问题。我加了标签。
是否使用的是单声道的版本? ('mono --version') – GTHvidsten
我使用的是'4.2.3'版本 – Rhs
哪个SignalR DLL在您的执行文件夹中? (我必须同时使用'Microsoft.AspNet.SignalR.Core.dll'和'Microsoft.AspNet.SignalR.SystemWeb.dll') – GTHvidsten