我正在尝试使用 WebSite 实现最简单的示例(https://github.com/SignalR/SignalR/wiki/QuickStart-Hubs)(我一直在尝试 WebForms 但遗憾的是结果相同)
在Monitor.cs
using System;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
[HubName("chat")]
public class Chat : Hub {
public void Send(string message) {
// Call the addMessage method on all clients
Clients.All.addMessage(message);
}
}
在Global.asax
<%@ Application Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web.Routing" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RouteTable.Routes.MapHubs();
}
在Default.aspx
<%@ Page Title="Monitor" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Monitor.aspx.cs" Inherits="Monitor" %>
<asp:Content ID="MonitorHeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript" src="Scripts/jquery-1.6.4.min.js"></script>
<script src="Scripts/jquery.signalR-1.0.0.min.js" type="text/javascript"></script>
<script src="/signalr/hubs" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
// Proxy created on the fly
var chat = $.connection.chat;
// Declare a function on the chat hub so the server can invoke it
chat.client.addMessage = function (message) {
$('#messages').append('<li>' + message + '</li>');
};
// Start the connection
$.connection.hub.start().done(function () {
$("#broadcast").click(function () {
// Call the chat method on the server
chat.server.send($('#msg').val());
});
});
});
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<input type="text" id="msg" />
<input type="button" id="broadcast" value="broadcast" />
<ul id="messages">
</asp:Content>
它不起作用,当我点击/signalr/hubs
我得到
<span><h1>Server Error in 'XXX' Application.<hr width=100% size=1 color=silver></h1>
<h2> <i>HTTP Error 404 - Not Found.</i> </h2></span>
我究竟做错了什么?